Class BitInputStream

  • All Implemented Interfaces:
    BitReader

    public class BitInputStream
    extends java.lang.Object
    implements BitReader
    This is a big endian bit reader. It reads its bits from an InputStream.
    • Constructor Summary

      Constructors 
      Constructor Description
      BitInputStream​(Stream in)
      Make a BitReader from an InputStream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean bit()
      Read one bit.
      long nrBits()
      Get the number of bits that have been read from this BitInputStream.
      boolean pad​(int width)
      Check that the rest of the block has been padded with zeroes.
      int read​(int width)
      Read some bits.
      • Methods inherited from class java.lang.Object

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

      • BitInputStream

        public BitInputStream​(Stream in)
        Make a BitReader from an InputStream. The BitReader will take bytes from the InputStream and unpack them into bits.
        Parameters:
        in - An InputStream.
    • Method Detail

      • nrBits

        public long nrBits()
        Get the number of bits that have been read from this BitInputStream. This includes pad bits that have been skipped, but might not include bytes that have been read from the underlying InputStream that have not yet been delivered as bits.
        Specified by:
        nrBits in interface BitReader
        Returns:
        The number of bits read so far.
      • pad

        public boolean pad​(int width)
                    throws IOException
        Check that the rest of the block has been padded with zeroes.
        Specified by:
        pad in interface BitReader
        Parameters:
        width - The size of the block to pad in bits. This will typically be 8, 16, 32, 64, 128, 256, etc.
        Returns:
        true if the block was zero padded, or false if the the padding contains any one bits.
        Throws:
        IOException
      • read

        public int read​(int width)
                 throws IOException
        Read some bits.
        Specified by:
        read in interface BitReader
        Parameters:
        width - The number of bits to read. (0..32)
        Returns:
        the bits
        Throws:
        IOException