Class BitReader


  • final class BitReader
    extends java.lang.Object
    Bit reading helpers.
    • Field Detail

      • CAPACITY

        private static final int CAPACITY
        Input byte buffer, consist of a ring-buffer and a "slack" region where bytes from the start of the ring-buffer are copied.
        See Also:
        Constant Field Values
      • byteBuffer

        private final byte[] byteBuffer
      • intBuffer

        private final int[] intBuffer
      • intReader

        private final IntReader intReader
      • input

        private java.io.InputStream input
      • endOfStreamReached

        private boolean endOfStreamReached
        Input stream is finished.
      • accumulator

        long accumulator
        Pre-fetched bits.
      • bitOffset

        int bitOffset
        Current bit-reading position in accumulator.
      • intOffset

        private int intOffset
        Offset of next item in intBuffer.
      • tailBytes

        private int tailBytes
    • Constructor Detail

      • BitReader

        BitReader()
    • Method Detail

      • readMoreInput

        static void readMoreInput​(BitReader br)
        Fills up the input buffer.

        No-op if there are at least 36 bytes present after current position.

        After encountering the end of the input stream, 64 additional zero bytes are copied to the buffer.

      • checkHealth

        static void checkHealth​(BitReader br,
                                boolean endOfStream)
      • fillBitWindow

        static void fillBitWindow​(BitReader br)
        Advances the Read buffer by 5 bytes to make room for reading next 24 bits.
      • readBits

        static int readBits​(BitReader br,
                            int n)
        Reads the specified number of bits from Read Buffer.
      • init

        static void init​(BitReader br,
                         java.io.InputStream input)
        Initialize bit reader.

        Initialisation turns bit reader to a ready state. Also a number of bytes is prefetched to accumulator. Because of that this method may block until enough data could be read from input.

        Parameters:
        br - BitReader POJO
        input - data source
      • prepare

        private static void prepare​(BitReader br)
      • reload

        static void reload​(BitReader br)
      • close

        static void close​(BitReader br)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • jumpToByteBoundary

        static void jumpToByteBoundary​(BitReader br)
      • intAvailable

        static int intAvailable​(BitReader br)
      • copyBytes

        static void copyBytes​(BitReader br,
                              byte[] data,
                              int offset,
                              int length)