Interface BitInputStream

All Known Implementing Classes:
ByteArrayBitInputStream

public interface BitInputStream
An interface with methods allowing bit-wise reading from an input stream. All methods in this interface are optional and an implementation not support a method or a specific state (e.g. endian) will throw an UnsupportedOperationException if such a method is being called. This should be specified in the implementation documentation.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    constant for setting this stream's mode to big endian
    static final int
    constant for setting this stream's mode to little endian
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    causes the read pointer to be moved to the beginning of the next byte, remaining bits in the current byte are discarded
    boolean
    reads one bit (as a boolean) from the input stream
    int
    getInt(int bits)
    reads bits number of bits from the input stream
    int
    reads a huffman codeword based on the root parameter and returns the decoded value
    long
    getLong(int bits)
    reads bits number of bits from the input stream
    int
    getSignedInt(int bits)
    reads bits number of bits from the input stream
    int
     
    int
    readSignedRice(int order)
    reads an integer encoded as "signed rice" as described in the FLAC audio format specification
    void
    readSignedRice(int order, int[] buffer, int offset, int len)
    fills the array from offset with len integers encoded as "signed rice" as described in the FLAC audio format specification
    void
    setEndian(int endian)
    changes the endian mode used when reading bit-wise from the stream, changing the mode mid-stream will cause the read cursor to move to the beginning of the next byte (as if calling the align method
    void
    skip(int length)
     
  • Field Details

  • Method Details

    • getBit

      boolean getBit() throws IOException
      reads one bit (as a boolean) from the input stream
      Returns:
      true if the next bit is 1, false otherwise
      Throws:
      IOException - if an I/O error occurs
      UnsupportedOperationException - if the method is not supported by the implementation
    • getInt

      int getInt(int bits) throws IOException
      reads bits number of bits from the input stream
      Parameters:
      bits -
      Returns:
      the unsigned integer value read from the stream
      Throws:
      IOException - if an I/O error occurs
      UnsupportedOperationException - if the method is not supported by the implementation
    • getSignedInt

      int getSignedInt(int bits) throws IOException
      reads bits number of bits from the input stream
      Parameters:
      bits -
      Returns:
      the signed integer value read from the stream
      Throws:
      IOException - if an I/O error occurs
      UnsupportedOperationException - if the method is not supported by the implementation
    • getInt

      int getInt(HuffmanNode root) throws IOException
      reads a huffman codeword based on the root parameter and returns the decoded value
      Parameters:
      root - the root of the Huffman tree used to decode the codeword
      Returns:
      the decoded unsigned integer value read from the stream
      Throws:
      IOException - if an I/O error occurs
      UnsupportedOperationException - if the method is not supported by the implementation
    • readSignedRice

      int readSignedRice(int order) throws IOException
      reads an integer encoded as "signed rice" as described in the FLAC audio format specification
      Parameters:
      order -
      Returns:
      the decoded integer value read from the stream
      Throws:
      IOException - if an I/O error occurs
      UnsupportedOperationException - if the method is not supported by the implementation
    • readSignedRice

      void readSignedRice(int order, int[] buffer, int offset, int len) throws IOException
      fills the array from offset with len integers encoded as "signed rice" as described in the FLAC audio format specification
      Parameters:
      order -
      buffer -
      offset -
      len -
      Throws:
      IOException - if an I/O error occurs
      UnsupportedOperationException - if the method is not supported by the implementation
    • getLong

      long getLong(int bits) throws IOException
      reads bits number of bits from the input stream
      Parameters:
      bits -
      Returns:
      the unsigned long value read from the stream
      Throws:
      IOException - if an I/O error occurs
      UnsupportedOperationException - if the method is not supported by the implementation
    • align

      void align()
      causes the read pointer to be moved to the beginning of the next byte, remaining bits in the current byte are discarded
      Throws:
      UnsupportedOperationException - if the method is not supported by the implementation
    • setEndian

      void setEndian(int endian)
      changes the endian mode used when reading bit-wise from the stream, changing the mode mid-stream will cause the read cursor to move to the beginning of the next byte (as if calling the align method
      Parameters:
      endian -
      Throws:
      UnsupportedOperationException - if the method is not supported by the implementation
      See Also:
    • position

      int position()
    • skip

      void skip(int length)