Package de.jarnbjo.util.io
Class ByteArrayBitInputStream
java.lang.Object
de.jarnbjo.util.io.ByteArrayBitInputStream
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionByteArrayBitInputStream(byte[] source) ByteArrayBitInputStream(byte[] source, int endian) -
Method Summary
Modifier and TypeMethodDescriptionvoidalign()causes the read pointer to be moved to the beginning of the next byte, remaining bits in the current byte are discardedbooleangetBit()reads one bit (as a boolean) from the input streamintgetInt(int bits) readsbitsnumber of bits from the input streamintgetInt(HuffmanNode root) reads a huffman codeword based on therootparameter and returns the decoded valuelonggetLong(int bits) readsbitsnumber of bits from the input streamintgetSignedInt(int bits) readsbitsnumber of bits from the input streambyte[]intposition()intreadSignedRice(int order) reads an integer encoded as "signed rice" as described in the FLAC audio format specificationvoidreadSignedRice(int order, int[] buffer, int off, int len) fills the array fromoffsetwithlenintegers encoded as "signed rice" as described in the FLAC audio format specificationvoidsetEndian(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 thealignmethodvoidskip(int length)
-
Constructor Details
-
ByteArrayBitInputStream
public ByteArrayBitInputStream(byte[] source) -
ByteArrayBitInputStream
public ByteArrayBitInputStream(byte[] source, int endian)
-
-
Method Details
-
getBit
Description copied from interface:BitInputStreamreads one bit (as a boolean) from the input stream- Specified by:
getBitin interfaceBitInputStream- Returns:
trueif the next bit is 1,falseotherwise- Throws:
IOException- if an I/O error occurs
-
getInt
Description copied from interface:BitInputStreamreadsbitsnumber of bits from the input stream- Specified by:
getIntin interfaceBitInputStream- Returns:
- the unsigned integer value read from the stream
- Throws:
IOException- if an I/O error occurs
-
getSignedInt
Description copied from interface:BitInputStreamreadsbitsnumber of bits from the input stream- Specified by:
getSignedIntin interfaceBitInputStream- Returns:
- the signed integer value read from the stream
- Throws:
IOException- if an I/O error occurs
-
getInt
Description copied from interface:BitInputStreamreads a huffman codeword based on therootparameter and returns the decoded value- Specified by:
getIntin interfaceBitInputStream- 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
Description copied from interface:BitInputStreamreadsbitsnumber of bits from the input stream- Specified by:
getLongin interfaceBitInputStream- Returns:
- the unsigned long value read from the stream
- Throws:
IOException- if an I/O error occurs
-
readSignedRice
reads an integer encoded as "signed rice" as described in the FLAC audio format specification
not supported for little endian
- Specified by:
readSignedRicein interfaceBitInputStream- Parameters:
order-- Returns:
- the decoded integer value read from the stream
- Throws:
IOException- if an I/O error occursUnsupportedOperationException- if the method is not supported by the implementation
-
readSignedRice
fills the array from
offsetwithlenintegers encoded as "signed rice" as described in the FLAC audio format specificationnot supported for little endian
- Specified by:
readSignedRicein interfaceBitInputStream- Parameters:
order-buffer-off- offsetlen-- Throws:
IOException- if an I/O error occursUnsupportedOperationException- if the method is not supported by the implementation
-
align
public void align()Description copied from interface:BitInputStreamcauses the read pointer to be moved to the beginning of the next byte, remaining bits in the current byte are discarded- Specified by:
alignin interfaceBitInputStream
-
setEndian
public void setEndian(int endian) Description copied from interface:BitInputStreamchanges 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 thealignmethod- Specified by:
setEndianin interfaceBitInputStream- See Also:
-
getSource
public byte[] getSource()- Returns:
- the byte array used as a source for this instance
-
position
public int position()- Specified by:
positionin interfaceBitInputStream
-
skip
public void skip(int length) - Specified by:
skipin interfaceBitInputStream
-