Class BitStreamReader

  • Direct Known Subclasses:
    BitBufferReader

    public class BitStreamReader
    extends java.lang.Object
    Helper for reading a specific number of bits at a time from a stream.
    • Constructor Summary

      Constructors 
      Constructor Description
      BitStreamReader​(java.io.InputStream stream)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int asInteger​(int bitsNeeded)
      Get the specified number of bits as an integer value
      long asLong​(int bitsNeeded)
      Get the specified number of bits as a long value
      int asSignedInteger​(int bitsNeeded)
      Get the specific number of bits as a signed integer value (highest order bit is sign)
      long asSignedLong​(int bitsNeeded)
      Get the specific number of bits as a signed long value (highest order bit is sign)
      int readAllZeroes()
      Reads bits from the stream until a set bit is reached.
      protected int readByte()  
      int readRemainingBits()
      Reads the number of bits it requires to make the reader align on a byte.
      • Methods inherited from class java.lang.Object

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

      • BitStreamReader

        public BitStreamReader​(java.io.InputStream stream)
        Parameters:
        stream - The underlying stream
    • Method Detail

      • asLong

        public long asLong​(int bitsNeeded)
                    throws java.io.IOException
        Get the specified number of bits as a long value
        Parameters:
        bitsNeeded - Number of bits to retrieve
        Returns:
        The value of those bits as a long
        Throws:
        java.io.IOException - On read error
      • asSignedLong

        public long asSignedLong​(int bitsNeeded)
                          throws java.io.IOException
        Get the specific number of bits as a signed long value (highest order bit is sign)
        Parameters:
        bitsNeeded - Number of bits needed
        Returns:
        The signed value
        Throws:
        java.io.IOException - On read error
      • asInteger

        public int asInteger​(int bitsNeeded)
                      throws java.io.IOException
        Get the specified number of bits as an integer value
        Parameters:
        bitsNeeded - Number of bits to retrieve
        Returns:
        The value of those bits as an integer
        Throws:
        java.io.IOException - On read error
      • asSignedInteger

        public int asSignedInteger​(int bitsNeeded)
                            throws java.io.IOException
        Get the specific number of bits as a signed integer value (highest order bit is sign)
        Parameters:
        bitsNeeded - Number of bits needed
        Returns:
        The signed value
        Throws:
        java.io.IOException - On read error
      • readAllZeroes

        public int readAllZeroes()
                          throws java.io.IOException
        Reads bits from the stream until a set bit is reached.
        Returns:
        The number of zeroes read
        Throws:
        java.io.IOException - On read error
      • readRemainingBits

        public int readRemainingBits()
        Reads the number of bits it requires to make the reader align on a byte.
        Returns:
        The read bits as an unsigned value
      • readByte

        protected int readByte()
                        throws java.io.IOException
        Throws:
        java.io.IOException