All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mapdb.DataInput2 Maven / Gradle / Ivy

Go to download

MapDB provides concurrent Maps, Sets and Queues backed by disk storage or off-heap memory. It is a fast, scalable and easy to use embedded Java database.

There is a newer version: 3.1.0
Show newest version
package org.mapdb;

import java.io.*;

/**
 * Used for serialization
 */
public abstract class DataInput2 implements DataInput {


    /** DataInput on top of {@code byte[]} */
    public static final class ByteArray extends DataInput2 {
        protected final byte[] buf;
        public int pos;

        public ByteArray(byte[] b) {
            this(b, 0);
        }

        public ByteArray(byte[] bb, int pos) {
            //$DELAY$
            buf = bb;
            this.pos = pos;
        }

        @Override
        public void readFully(byte[] b, int off, int len) throws IOException {
            System.arraycopy(buf, pos, b, off, len);
            //$DELAY$
            pos += len;
        }

        @Override
        public int skipBytes(final int n) throws IOException {
            pos += n;
            //$DELAY$
            return n;
        }

        @Override
        public boolean readBoolean() throws IOException {
            //$DELAY$
            return buf[pos++] == 1;
        }

        @Override
        public byte readByte() throws IOException {
            //$DELAY$
            return buf[pos++];
        }

        @Override
        public int readUnsignedByte() throws IOException {
            //$DELAY$
            return buf[pos++] & 0xff;
        }

        @Override
        public short readShort() throws IOException {
            //$DELAY$
            return (short)((buf[pos++] << 8) | (buf[pos++] & 0xff));
        }

        @Override
        public char readChar() throws IOException {
            //$DELAY$
            return (char) (
                    ((buf[pos++] & 0xff) << 8) |
                            (buf[pos++] & 0xff));
        }

        @Override
        public int readInt() throws IOException {
            int p = pos;
            final byte[] b = buf;
            final int ret =
                    ((((int)b[p++]) << 24) |
                            (((int)b[p++] & 0xFF) << 16) |
                            (((int)b[p++] & 0xFF) <<  8) |
                            (((int)b[p++] & 0xFF)));
            pos = p;
            return ret;
        }

        @Override
        public long readLong() throws IOException {
            int p = pos;
            final byte[] b = buf;
            final long ret =
                    ((((long)b[p++]) << 56) |
                            (((long)b[p++] & 0xFF) << 48) |
                            (((long)b[p++] & 0xFF) << 40) |
                            (((long)b[p++] & 0xFF) << 32) |
                            (((long)b[p++] & 0xFF) << 24) |
                            (((long)b[p++] & 0xFF) << 16) |
                            (((long)b[p++] & 0xFF) <<  8) |
                            (((long)b[p++] & 0xFF)));
            pos = p;
            return ret;
        }



        @Override
        public int getPos() {
            return pos;
        }

        @Override
        public void setPos(int pos) {
            this.pos = pos;
        }

        @Override
        public byte[] internalByteArray() {
            return buf;
        }

        @Override
        public java.nio.ByteBuffer internalByteBuffer() {
            return null;
        }

        @Override
        public void close() {
        }

        @Override
        public long unpackLong() throws IOException {
            byte[] b = buf;
            int p = pos;
            long ret = 0;
            byte v;
            do{
                //$DELAY$
                v = b[p++];
                ret = (ret<<7 ) | (v & 0x7F);
            }while((v&0x80)==0);
            pos = p;
            return ret;
        }

        @Override
        public void unpackLongSkip(int count) {
            byte[] b = buf;
            int pos2 = this.pos;
            while(count>0){
                count -= (b[pos2++]&0x80)>>7;
            }
            this.pos = pos2;
        }


        @Override
        public int unpackInt() throws IOException {
            byte[] b = buf;
            int p = pos;
            int ret = 0;
            byte v;
            do{
                //$DELAY$
                v = b[p++];
                ret = (ret<<7 ) | (v & 0x7F);
            }while((v&0x80)==0);
            pos = p;
            return ret;
        }

        @Override
        public long[] unpackLongArrayDeltaCompression(final int size) throws IOException {
            long[] ret = new long[size];
            int pos2 = pos;
            byte[] buf2 = buf;
            long prev =0;
            byte v;
            for(int i=0;i0){
                count -= (buf2.get(pos2++)&0x80)>>7;
            }
            pos = pos2;
        }


        @Override
        public void unpackIntArray(int[] array, int start, int end) {
            int pos2 = pos;
            java.nio.ByteBuffer buf2 = buf;
            int ret;
            byte v;
            for(;start0){
                unpackLong();
            }
        }




        @Override
        public int getPos() {
            throw new UnsupportedOperationException("InputStream does not support pos");
        }

        @Override
        public void setPos(int pos) {
            throw new UnsupportedOperationException("InputStream does not support pos");
        }

        @Override
        public byte[] internalByteArray() {
            return null;
        }

        @Override
        public java.nio.ByteBuffer internalByteBuffer() {
            return null;
        }

        @Override
        public void close() {
        }

        @Override
        public long unpackLong() throws IOException {
            return DataIO.unpackLong(ins);
        }

        @Override
        public int unpackInt() throws IOException {
            return DataIO.unpackInt(ins);
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy