Class BinaryInputStream

    • Constructor Detail

      • BinaryInputStream

        public BinaryInputStream​(InputStream in)
    • Method Detail

      • read

        public int read()
                 throws IOException
        Read a single byte.
        Specified by:
        read in class InputStream
        Returns:
        the byte value, or -1 if end of stream.
        Throws:
        IOException - if unable to read from stream.
      • read

        public int read​(byte[] out)
                 throws IOException
        Read binary data from stream.
        Overrides:
        read in class InputStream
        Parameters:
        out - The output buffer to read into.
        Throws:
        IOException - if unable to read from stream.
      • read

        public int read​(byte[] out,
                        int off,
                        int len)
                 throws IOException
        Read binary data from stream.
        Overrides:
        read in class InputStream
        Parameters:
        out - The output buffer to read into.
        off - Offset in out array to writeBinary to.
        len - Number of bytes to read.
        Throws:
        IOException - if unable to read from stream.
      • mark

        public void mark​(int readLimit)
        Overrides:
        mark in class InputStream
      • expect

        public void expect​(byte[] out)
                    throws IOException
        Read binary data from stream.
        Parameters:
        out - The output buffer to read into.
        Throws:
        IOException - if unable to read from stream.
      • expectByte

        public byte expectByte()
                        throws IOException
        Read a byte from the input stream.
        Returns:
        The number read.
        Throws:
        IOException - If no byte to read.
      • expectShort

        public short expectShort()
                          throws IOException
        Read a short from the input stream.
        Returns:
        The number read.
        Throws:
        IOException - if unable to read from stream.
      • expectInt

        public int expectInt()
                      throws IOException
        Read an int from the input stream.
        Returns:
        The number read.
        Throws:
        IOException - if unable to read from stream.
      • expectLong

        public long expectLong()
                        throws IOException
        Read a long int from the input stream.
        Returns:
        The number read.
        Throws:
        IOException - if unable to read from stream.
      • expectFloat

        public float expectFloat()
                          throws IOException
        Read a float from the input stream.
        Returns:
        The number read.
        Throws:
        IOException - if unable to read from stream.
      • expectDouble

        public double expectDouble()
                            throws IOException
        Read a double from the input stream.
        Returns:
        The number read.
        Throws:
        IOException - if unable to read from stream.
      • expectBytes

        public byte[] expectBytes​(int bytes)
                           throws IOException
        Read binary data from stream.
        Parameters:
        bytes - Number of bytes to read.
        Returns:
        The binary wrapper.
        Throws:
        IOException - if unable to read from stream.
      • expectUInt8

        public int expectUInt8()
                        throws IOException
        Read an unsigned byte from the input stream.
        Returns:
        Unsigned byte.
        Throws:
        IOException - If no number to read.
      • expectUInt16

        public int expectUInt16()
                         throws IOException
        Read an unsigned short from the input stream.
        Returns:
        The number read.
        Throws:
        IOException - If no number to read.
      • readUInt16

        public int readUInt16()
                       throws IOException
        Read an unsigned short from the input stream.
        Returns:
        The number read.
        Throws:
        IOException - If no number to read.
      • expectUInt24

        public int expectUInt24()
                         throws IOException
        Read an unsigned short from the input stream.
        Returns:
        The number read.
        Throws:
        IOException - If no number to read.
      • expectUInt32

        public int expectUInt32()
                         throws IOException
        Read an unsigned int from the input stream.
        Returns:
        The number read.
        Throws:
        IOException - If no number to read.
      • expectUnsigned

        public int expectUnsigned​(int bytes)
                           throws IOException
        Read an unsigned number from the input stream.
        Parameters:
        bytes - Number of bytes to read.
        Returns:
        The number read.
        Throws:
        IOException - if unable to read from stream.
      • expectUnsignedLong

        public long expectUnsignedLong​(int bytes)
                                throws IOException
        Read an unsigned number from the input stream.
        Parameters:
        bytes - Number of bytes to read.
        Returns:
        The number read.
        Throws:
        IOException - if unable to read from stream.
      • expectSigned

        public long expectSigned​(int bytes)
                          throws IOException
        Read an signed number from the input stream.
        Parameters:
        bytes - Number of bytes to read.
        Returns:
        The number read.
        Throws:
        IOException - if unable to read from stream.
      • readIntZigzag

        public int readIntZigzag()
                          throws IOException
        Read a long number as zigzag encoded from the stream. The least significant bit becomes the sign, and the actual value is absolute and shifted one bit. This makes it maximum compressed both when positive and negative.
        Returns:
        The zigzag decoded value.
        Throws:
        IOException - if unable to read from stream.
      • expectIntZigzag

        public int expectIntZigzag()
                            throws IOException
        Read a long number as zigzag encoded from the stream. The least significant bit becomes the sign, and the actual value is absolute and shifted one bit. This makes it maximum compressed both when positive and negative.
        Returns:
        The zigzag decoded value.
        Throws:
        IOException - if unable to read from stream.
      • readLongZigzag

        public long readLongZigzag()
                            throws IOException
        Read a long number as zigzag encoded from the stream. The least significant bit becomes the sign, and the actual value is absolute and shifted one bit. This makes it maximum compressed both when positive and negative.
        Returns:
        The zigzag decoded value.
        Throws:
        IOException - if unable to read from stream.
      • expectLongZigzag

        public long expectLongZigzag()
                              throws IOException
        Read a long number as zigzag encoded from the stream. The least significant bit becomes the sign, and the actual value is absolute and shifted one bit. This makes it maximum compressed both when positive and negative.
        Returns:
        The zigzag decoded value.
        Throws:
        IOException - if unable to read from stream.
      • readIntBase128

        public int readIntBase128()
                           throws IOException
        Read a signed number as base128 (integer with variable number of bytes, determined as part of the bytes themselves), using the endianness to determine order of 7-byte block assembly.

        NOTE: Reading base128 accepts end of stream as '0'.

        Returns:
        The base128 number read from stream.
        Throws:
        IOException - if unable to read from stream.
      • expectIntBase128

        public int expectIntBase128()
                             throws IOException
        Read a signed number as base128 (integer with variable number of bytes, determined as part of the bytes themselves), using the endianness to determine order of 7-byte block assembly.
        Returns:
        The base128 number read from stream.
        Throws:
        IOException - if unable to read from stream.
      • readLongBase128

        public long readLongBase128()
                             throws IOException
        Read a signed number as base128 (integer with variable number of bytes, determined as part of the bytes themselves), using the endianness to determine order of 7-byte block assembly.

        NOTE: Reading base128 accepts end of stream as '0'.

        Returns:
        The base128 number read from stream.
        Throws:
        IOException - if unable to read from stream.
      • expectLongBase128

        public long expectLongBase128()
                               throws IOException
        Read a signed number as base128 (integer with variable number of bytes, determined as part of the bytes themselves), using the endianness to determine order of 7-byte block assembly.
        Returns:
        The base128 number read from stream.
        Throws:
        IOException - if unable to read from stream.
      • internalReadIntBase128

        protected abstract int internalReadIntBase128​(int i)
                                               throws IOException
        Throws:
        IOException
      • internalReadLongBase128

        protected abstract long internalReadLongBase128​(int i)
                                                 throws IOException
        Throws:
        IOException
      • unshift2bytes

        protected abstract int unshift2bytes​(int b1,
                                             int b2)
      • unshift3bytes

        protected abstract int unshift3bytes​(int b1,
                                             int b2,
                                             int b3)
      • unshift4bytes

        protected abstract int unshift4bytes​(int b1,
                                             int b2,
                                             int b3,
                                             int b4)
      • unshift8bytes

        protected abstract long unshift8bytes​(long b1,
                                              long b2,
                                              long b3,
                                              long b4,
                                              long b5,
                                              long b6,
                                              long b7,
                                              long b8)
      • unshiftNBytes

        protected abstract long unshiftNBytes​(byte[] bytes)