Interface BitInput

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      default long align()
      Aligns to a single byte by discarding bits.
      long align​(int bytes)
      Aligns to specified number of bytes by discarding bits.
      default void close()
      Closes this input and releases any system resources associated with it.
      default boolean readBoolean()
      Reads a 1-bit boolean value.
      default byte readByte​(boolean unsigned, int size)
      Reads a byte value of specified number of bits.
      default byte readByte​(int size)
      Reads a signed byte value of specified number of bits.
      default byte readByte8()
      Reads a 8-bit signed byte value.
      default char readChar​(int size)
      Reads a char value of specified bit size.
      default char readChar16()
      Reads a 16-bit char value.
      default double readDouble64()
      Reads a 64-bit double value.
      default float readFloat32()
      Reads a 32-bit float value.
      int readInt​(boolean unsigned, int size)
      Reads an int value of specified number of bits.
      default int readInt​(int size)
      Reads a signed int value of specified bit size.
      default int readInt32()
      Reads a 32-bit signed int value.
      default int readInt32Le()
      Deprecated.
      Reads a value with readInt32() method and reverse bytes with Integer.reverseBytes(int) method.
      default long readLong​(boolean unsigned, int size)
      Reads a long value of specified number of bits.
      default long readLong​(int size)
      Reads a signed long value of specified bit size.
      default long readLong64()
      Reads a 64-bit signed long value.
      default long readLong64Le()
      Deprecated.
      Reads a value with readLong64() and reverse bytes with Long.reverseBytes(long) method.
      default short readShort​(boolean unsigned, int size)
      Reads a short value of specified number of bits.
      default short readShort​(int size)
      Reads a signed short value of specified number of bits.
      default short readShort16()
      Reads a 16-bit signed short value.
      default short readShort16Le()
      Deprecated.
      Reads a value with readShort16() and reverse bytes with Short.reverseBytes(short) method.
      default byte readUnsignedByte​(int size)
      Reads an unsigned byte value of specified number of bits.
      default int readUnsignedInt​(int size)
      Reads an unsigned int value of specified bit size.
      default long readUnsignedLong​(int size)
      Reads an unsigned long value of specified bit size.
      default short readUnsignedShort​(int size)
      Reads an unsigned short value of specified number of bits.
      default <T> T readValue​(ValueAdapter<? extends T> adapter)
      Reads a value using specified adapter.
      default void skip​(int bits)
      Skips specified number of bits by discarding bits.
    • Method Detail

      • close

        default void close()
                    throws IOException
        Closes this input and releases any system resources associated with it. The close method of BitInput interface does nothing.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Throws:
        IOException - if an I/O error occurs.
      • readBoolean

        default boolean readBoolean()
                             throws IOException
        Reads a 1-bit boolean value. This method reads a 1-bit unsigned int value and returns true for 0b1 and false for 0b0.
        Returns:
        the value read.
        Throws:
        IOException - if an I/O error occurs.
      • readByte

        default byte readByte​(boolean unsigned,
                              int size)
                       throws IOException
        Reads a byte value of specified number of bits.
        Parameters:
        unsigned - a flag for indicating unsigned value; true for unsigned, false for signed.
        size - the number of bits to read; between 1 and (8 - ( unsigned ? 1 : 0)), both inclusive.
        Returns:
        a byte value of specified bit size.
        Throws:
        IOException - if an I/O error occurs.
      • readByte

        default byte readByte​(int size)
                       throws IOException
        Reads a signed byte value of specified number of bits.
        Parameters:
        size - the number of bits to read; between 1 and 8, both inclusive.
        Returns:
        a signed byte value of specified bit size.
        Throws:
        IOException - if an I/O error occurs.
      • readByte8

        default byte readByte8()
                        throws IOException
        Reads a 8-bit signed byte value.
        Returns:
        a signed 8-bit byte value.
        Throws:
        IOException - if an I/O error occurs.
      • readUnsignedByte

        default byte readUnsignedByte​(int size)
                               throws IOException
        Reads an unsigned byte value of specified number of bits.
        Parameters:
        size - the number of bits to read; between 1 (inclusive) and 8 (exclusive).
        Returns:
        an unsigned byte value of specified bit size.
        Throws:
        IOException - if an I/O error occurs.
      • readShort

        default short readShort​(boolean unsigned,
                                int size)
                         throws IOException
        Reads a short value of specified number of bits.
        Parameters:
        unsigned - a flag for indicating unsigned value; true for unsigned, false for signed.
        size - the number of bits to read; between 1 and (16 - (unsigned ? 1 : 0)), both inclusive.
        Returns:
        a short value of specified size.
        Throws:
        IOException - if an I/O error occurs.
      • readShort

        default short readShort​(int size)
                         throws IOException
        Reads a signed short value of specified number of bits.
        Parameters:
        size - the number of bits to read; between 1 and 16, both inclusive.
        Returns:
        a signed short value of specified bit size.
        Throws:
        IOException - if an I/O error occurs.
      • readShort16

        default short readShort16()
                           throws IOException
        Reads a 16-bit signed short value.
        Returns:
        a 16-bit signed short value read.
        Throws:
        IOException - if an I/O error occurs.
        See Also:
        readShort(int)
      • readUnsignedShort

        default short readUnsignedShort​(int size)
                                 throws IOException
        Reads an unsigned short value of specified number of bits.
        Parameters:
        size - the number of bits to read; between 1 (inclusive) and 16 (exclusive).
        Returns:
        an unsigned short value of specified bit size.
        Throws:
        IOException - if an I/O error occurs.
      • readInt

        int readInt​(boolean unsigned,
                    int size)
             throws IOException
        Reads an int value of specified number of bits.
        Parameters:
        unsigned - a flag for indicating unsigned value; true for unsigned, false for signed.
        size - the number of bits to read; between 1 and (32 - ( unsigned ? 1: 0)), both inclusive.
        Returns:
        an int value of specified size.
        Throws:
        IOException - if an I/O error occurs.
      • readInt

        default int readInt​(int size)
                     throws IOException
        Reads a signed int value of specified bit size.
        Parameters:
        size - the number of bits to read; between 1 and 32, both inclusive.
        Returns:
        a signed int value.
        Throws:
        IOException - if an I/O error occurs.
      • readInt32

        default int readInt32()
                       throws IOException
        Reads a 32-bit signed int value.
        Returns:
        a 32-bit signed int value read.
        Throws:
        IOException - if an I/O error occurs.
      • readUnsignedInt

        default int readUnsignedInt​(int size)
                             throws IOException
        Reads an unsigned int value of specified bit size.
        Parameters:
        size - the number of bits to read; between 1 (inclusive) and 32 (exclusive).
        Returns:
        an unsigned int value.
        Throws:
        IOException - if an error occurs.
      • readLong

        default long readLong​(boolean unsigned,
                              int size)
                       throws IOException
        Reads a long value of specified number of bits.
        Parameters:
        unsigned - a flag for indicating unsigned value; true for unsigned, false for signed.
        size - the number of bits to read; between 1 and (64 - ( unsigned ? 1: 0)), both inclusive.
        Returns:
        a long value of specified bit size.
        Throws:
        IOException - if an I/O error occurs.
      • readLong

        default long readLong​(int size)
                       throws IOException
        Reads a signed long value of specified bit size.
        Parameters:
        size - the number of bits to read; between 1 and 64, both inclusive.
        Returns:
        a signed long value.
        Throws:
        IOException - if an I/O error occurs.
      • readLong64

        default long readLong64()
                         throws IOException
        Reads a 64-bit signed long value.
        Returns:
        a 64-bit signed long value.
        Throws:
        IOException - if an I/O error occurs.
      • readUnsignedLong

        default long readUnsignedLong​(int size)
                               throws IOException
        Reads an unsigned long value of specified bit size.
        Parameters:
        size - the number of bits to read; between 1 (inclusive) and 64 (exclusive).
        Returns:
        an unsigned long value.
        Throws:
        IOException - if an error occurs.
      • readChar

        default char readChar​(int size)
                       throws IOException
        Reads a char value of specified bit size.
        Parameters:
        size - the number of bits to read; between 1 and 16, both inclusive.
        Returns:
        a char value.
        Throws:
        IOException - if an I/O error occurs.
        See Also:
        readChar16()
      • readValue

        default <T> T readValue​(ValueAdapter<? extends T> adapter)
                         throws IOException
        Reads a value using specified adapter. The readValue(ValueAdapter) method of BitInput interface invokes ValueReader.read(BitInput) method with this.
        Type Parameters:
        T - value type parameter
        Parameters:
        adapter - the adapter.
        Returns:
        a value read.
        Throws:
        IOException - if an I/O error occurs.
      • skip

        default void skip​(int bits)
                   throws IOException
        Skips specified number of bits by discarding bits.
        Parameters:
        bits - the number of bit to skip; must be positive.
        Throws:
        IllegalArgumentException - if bits is not positive.
        IOException - if an I/O error occurs.
      • align

        long align​(int bytes)
            throws IOException
        Aligns to specified number of bytes by discarding bits.
        Parameters:
        bytes - the number of bytes to align; must be positive.
        Returns:
        the number of bits discarded while aligning.
        Throws:
        IllegalArgumentException - if bytes is not positive.
        IOException - if an I/O error occurs.
      • align

        default long align()
                    throws IOException
        Aligns to a single byte by discarding bits. The align() method of BitInput interface invokes align(int) with 1.
        Returns:
        the number of bits discarded while aligning.
        Throws:
        IOException - if an I/O error occurs.
        See Also:
        align(int)