Class ByteBitInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, BitInputStream

    public final class ByteBitInputStream
    extends java.lang.Object
    implements BitInputStream
    A stream of bits that can be read. Because they come from an underlying byte stream, the total number of bits is always a multiple of 8. The bits are read in little endian. Mutable and not thread-safe.
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteBitInputStream​(java.io.InputStream in)
      Constructs a bit input stream based on the specified byte input stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes this stream and the underlying input stream.
      int getBitPosition()
      Returns the current bit position, which ascends from 0 to 7 as bits are read.
      int read()
      Reads a bit from this stream.
      int readByte()
      Discards the remainder of the current byte (if any) and reads the next whole byte from the stream.
      int readNoEof()
      Reads a bit from this stream.
      • Methods inherited from class java.lang.Object

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

      • ByteBitInputStream

        public ByteBitInputStream​(java.io.InputStream in)
        Constructs a bit input stream based on the specified byte input stream.
        Parameters:
        in - the byte input stream (not null)
        Throws:
        java.lang.NullPointerException - if the input stream is null
    • Method Detail

      • getBitPosition

        public int getBitPosition()
        Description copied from interface: BitInputStream
        Returns the current bit position, which ascends from 0 to 7 as bits are read.
        Specified by:
        getBitPosition in interface BitInputStream
        Returns:
        the current bit position, which is between 0 and 7
      • readByte

        public int readByte()
                     throws java.io.IOException
        Description copied from interface: BitInputStream
        Discards the remainder of the current byte (if any) and reads the next whole byte from the stream. Returns -1 if the end of stream is reached.
        Specified by:
        readByte in interface BitInputStream
        Returns:
        the next byte from the stream, or -1 if the end of stream is reached
        Throws:
        java.io.IOException
      • read

        public int read()
                 throws java.io.IOException
        Description copied from interface: BitInputStream
        Reads a bit from this stream. Returns 0 or 1 if a bit is available, or -1 if the end of stream is reached. The end of stream always occurs on a byte boundary.
        Specified by:
        read in interface BitInputStream
        Returns:
        the next bit of 0 or 1, or -1 for the end of stream
        Throws:
        java.io.IOException - if an I/O exception occurred
      • readNoEof

        public int readNoEof()
                      throws java.io.IOException
        Description copied from interface: BitInputStream
        Reads a bit from this stream. Returns 0 or 1 if a bit is available, or throws an EOFException if the end of stream is reached. The end of stream always occurs on a byte boundary.
        Specified by:
        readNoEof in interface BitInputStream
        Returns:
        the next bit of 0 or 1
        Throws:
        java.io.IOException - if an I/O exception occurred
        java.io.EOFException - if the end of stream is reached
      • close

        public void close()
                   throws java.io.IOException
        Description copied from interface: BitInputStream
        Closes this stream and the underlying input stream.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface BitInputStream
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException - if an I/O exception occurred