Class Bzip2BitReader


  • class Bzip2BitReader
    extends java.lang.Object
    An bit reader that allows the reading of single bit booleans, bit strings of arbitrary length (up to 32 bits), and bit aligned 32-bit integers. A single byte at a time is read from the ByteBuf when more bits are required.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long bitBuffer
      A buffer of bits read from the input stream that have not yet been returned.
      private int bitCount
      The number of bits currently buffered in bitBuffer.
      private ByteBuf in
      The ByteBuf from which to read data.
      private static int MAX_COUNT_OF_READABLE_BYTES
      Maximum count of possible readable bytes to check.
    • Constructor Summary

      Constructors 
      Constructor Description
      Bzip2BitReader()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) boolean hasReadableBits​(int count)
      Checks that the specified number of bits available for reading.
      (package private) boolean hasReadableBytes​(int count)
      Checks that the specified number of bytes available for reading.
      (package private) boolean isReadable()
      Checks that at least one bit is available for reading.
      (package private) int readBits​(int count)
      Reads up to 32 bits from the ByteBuf.
      (package private) boolean readBoolean()
      Reads a single bit from the ByteBuf.
      (package private) int readInt()
      Reads 32 bits of input as an integer.
      (package private) void refill()
      Refill the ByteBuf by one byte.
      (package private) void setByteBuf​(ByteBuf in)
      Set the ByteBuf from which to read data.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MAX_COUNT_OF_READABLE_BYTES

        private static final int MAX_COUNT_OF_READABLE_BYTES
        Maximum count of possible readable bytes to check.
        See Also:
        Constant Field Values
      • bitBuffer

        private long bitBuffer
        A buffer of bits read from the input stream that have not yet been returned.
      • bitCount

        private int bitCount
        The number of bits currently buffered in bitBuffer.
    • Constructor Detail

      • Bzip2BitReader

        Bzip2BitReader()
    • Method Detail

      • setByteBuf

        void setByteBuf​(ByteBuf in)
        Set the ByteBuf from which to read data.
      • readBits

        int readBits​(int count)
        Reads up to 32 bits from the ByteBuf.
        Parameters:
        count - The number of bits to read (maximum 32 as a size of int)
        Returns:
        The bits requested, right-aligned within the integer
      • readBoolean

        boolean readBoolean()
        Reads a single bit from the ByteBuf.
        Returns:
        true if the bit read was 1, otherwise false
      • readInt

        int readInt()
        Reads 32 bits of input as an integer.
        Returns:
        The integer read
      • refill

        void refill()
        Refill the ByteBuf by one byte.
      • isReadable

        boolean isReadable()
        Checks that at least one bit is available for reading.
        Returns:
        true if one bit is available for reading, otherwise false
      • hasReadableBits

        boolean hasReadableBits​(int count)
        Checks that the specified number of bits available for reading.
        Parameters:
        count - The number of bits to check
        Returns:
        true if count bits are available for reading, otherwise false
      • hasReadableBytes

        boolean hasReadableBytes​(int count)
        Checks that the specified number of bytes available for reading.
        Parameters:
        count - The number of bytes to check
        Returns:
        true if count bytes are available for reading, otherwise false