Class LSBBitReader


  • public final class LSBBitReader
    extends java.lang.Object
    LSBBitReader
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int bitOffset  
      private long buffer
      Pre-buffers up to the next 8 Bytes in input.
      private javax.imageio.stream.ImageInputStream imageInput  
      private long streamPosition  
    • Constructor Summary

      Constructors 
      Constructor Description
      LSBBitReader​(javax.imageio.stream.ImageInputStream imageInput)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long peekBits​(int bits)
      Reads the specified number of bits from the buffer in an LSB-first way.
      int readBit()  
      long readBits​(int bits)
      Reads the specified number of bits from the stream in an LSB-first way and advances the bitOffset.
      private long readBits​(int bits, boolean peek)  
      private void refillBuffer()  
      private void resetBuffer()  
      • Methods inherited from class java.lang.Object

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

      • imageInput

        private final javax.imageio.stream.ImageInputStream imageInput
      • bitOffset

        private int bitOffset
      • streamPosition

        private long streamPosition
      • buffer

        private long buffer
        Pre-buffers up to the next 8 Bytes in input. Contains valid bits in bits 63 to bitOffset (inclusive).
    • Constructor Detail

      • LSBBitReader

        public LSBBitReader​(javax.imageio.stream.ImageInputStream imageInput)
    • Method Detail

      • readBits

        public long readBits​(int bits)
                      throws java.io.IOException
        Reads the specified number of bits from the stream in an LSB-first way and advances the bitOffset. The underlying ImageInputStream will be advanced to the first not (completely) read byte. Requesting more than 64 bits will advance the reader by the correct amount and return the lowest 64 bits of the read number
        Parameters:
        bits - the number of bits to read
        Returns:
        a signed long built from the requested bits (truncated to the low 64 bits)
        Throws:
        java.io.IOException - if an I/O error occurs
        See Also:
        peekBits(int)
      • peekBits

        public long peekBits​(int bits)
                      throws java.io.IOException
        Reads the specified number of bits from the buffer in an LSB-first way. Does not advance the bitOffset or the underlying input stream. As only 56 bits are buffered (in the worst case) peeking more is not possible without advancing the reader and as such disallowed.
        Parameters:
        bits - the number of bits to peek (max 56)
        Returns:
        a signed long built from the requested bits
        Throws:
        java.io.IOException - if an I/O error occurs
        See Also:
        readBits(int)
      • readBits

        private long readBits​(int bits,
                              boolean peek)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • refillBuffer

        private void refillBuffer()
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • resetBuffer

        private void resetBuffer()
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • readBit

        public int readBit()
                    throws java.io.IOException
        Throws:
        java.io.IOException