Class ByteArrayBitInputStream

java.lang.Object
de.jarnbjo.util.io.ByteArrayBitInputStream
All Implemented Interfaces:
BitInputStream

public class ByteArrayBitInputStream extends Object implements BitInputStream
Implementation of the BitInputStream interface, using a byte array as data source.
  • Field Summary

    Fields inherited from interface de.jarnbjo.util.io.BitInputStream

    BIG_ENDIAN, LITTLE_ENDIAN
  • Constructor Summary

    Constructors
    Constructor
    Description
    ByteArrayBitInputStream(byte[] source)
     
    ByteArrayBitInputStream(byte[] source, int 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
    byte[]
     
    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 off, 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)
     

    Methods inherited from class java.lang.Object

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

    • ByteArrayBitInputStream

      public ByteArrayBitInputStream(byte[] source)
    • ByteArrayBitInputStream

      public ByteArrayBitInputStream(byte[] source, int endian)
  • Method Details

    • getBit

      public boolean getBit() throws IOException
      Description copied from interface: BitInputStream
      reads one bit (as a boolean) from the input stream
      Specified by:
      getBit in interface BitInputStream
      Returns:
      true if the next bit is 1, false otherwise
      Throws:
      IOException - if an I/O error occurs
    • getInt

      public int getInt(int bits) throws IOException
      Description copied from interface: BitInputStream
      reads bits number of bits from the input stream
      Specified by:
      getInt in interface BitInputStream
      Returns:
      the unsigned integer value read from the stream
      Throws:
      IOException - if an I/O error occurs
    • getSignedInt

      public int getSignedInt(int bits) throws IOException
      Description copied from interface: BitInputStream
      reads bits number of bits from the input stream
      Specified by:
      getSignedInt in interface BitInputStream
      Returns:
      the signed integer value read from the stream
      Throws:
      IOException - if an I/O error occurs
    • getInt

      public int getInt(HuffmanNode root) throws IOException
      Description copied from interface: BitInputStream
      reads a huffman codeword based on the root parameter and returns the decoded value
      Specified by:
      getInt in interface BitInputStream
      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
    • getLong

      public long getLong(int bits) throws IOException
      Description copied from interface: BitInputStream
      reads bits number of bits from the input stream
      Specified by:
      getLong in interface BitInputStream
      Returns:
      the unsigned long value read from the stream
      Throws:
      IOException - if an I/O error occurs
    • readSignedRice

      public int readSignedRice(int order) throws IOException

      reads an integer encoded as "signed rice" as described in the FLAC audio format specification

      not supported for little endian

      Specified by:
      readSignedRice in interface BitInputStream
      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

      public void readSignedRice(int order, int[] buffer, int off, int len) throws IOException

      fills the array from offset with len integers encoded as "signed rice" as described in the FLAC audio format specification

      not supported for little endian

      Specified by:
      readSignedRice in interface BitInputStream
      Parameters:
      order -
      buffer -
      off - offset
      len -
      Throws:
      IOException - if an I/O error occurs
      UnsupportedOperationException - if the method is not supported by the implementation
    • align

      public void align()
      Description copied from interface: BitInputStream
      causes the read pointer to be moved to the beginning of the next byte, remaining bits in the current byte are discarded
      Specified by:
      align in interface BitInputStream
    • setEndian

      public void setEndian(int endian)
      Description copied from interface: BitInputStream
      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
      Specified by:
      setEndian in interface BitInputStream
      See Also:
    • getSource

      public byte[] getSource()
      Returns:
      the byte array used as a source for this instance
    • position

      public int position()
      Specified by:
      position in interface BitInputStream
    • skip

      public void skip(int length)
      Specified by:
      skip in interface BitInputStream