Package de.jarnbjo.util.io
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
FieldsModifier and TypeFieldDescriptionstatic final intconstant for setting this stream's mode to big endianstatic final intconstant for setting this stream's mode to little 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 streamintposition()intreadSignedRice(int order) reads an integer encoded as "signed rice" as described in the FLAC audio format specificationvoidreadSignedRice(int order, int[] buffer, int offset, 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)
-
Field Details
-
LITTLE_ENDIAN
static final int LITTLE_ENDIANconstant for setting this stream's mode to little endian- See Also:
-
BIG_ENDIAN
static final int BIG_ENDIANconstant for setting this stream's mode to big endian- See Also:
-
-
Method Details
-
getBit
reads one bit (as a boolean) from the input stream- Returns:
trueif the next bit is 1,falseotherwise- Throws:
IOException- if an I/O error occursUnsupportedOperationException- if the method is not supported by the implementation
-
getInt
readsbitsnumber of bits from the input stream- Parameters:
bits-- Returns:
- the unsigned integer value read from the stream
- Throws:
IOException- if an I/O error occursUnsupportedOperationException- if the method is not supported by the implementation
-
getSignedInt
readsbitsnumber of bits from the input stream- Parameters:
bits-- Returns:
- the signed integer value read from the stream
- Throws:
IOException- if an I/O error occursUnsupportedOperationException- if the method is not supported by the implementation
-
getInt
reads a huffman codeword based on therootparameter 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 occursUnsupportedOperationException- if the method is not supported by the implementation
-
readSignedRice
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 occursUnsupportedOperationException- if the method is not supported by the implementation
-
readSignedRice
fills the array fromoffsetwithlenintegers encoded as "signed rice" as described in the FLAC audio format specification- Parameters:
order-buffer-offset-len-- Throws:
IOException- if an I/O error occursUnsupportedOperationException- if the method is not supported by the implementation
-
getLong
readsbitsnumber of bits from the input stream- Parameters:
bits-- Returns:
- the unsigned long value read from the stream
- Throws:
IOException- if an I/O error occursUnsupportedOperationException- 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 thealignmethod- Parameters:
endian-- Throws:
UnsupportedOperationException- if the method is not supported by the implementation- See Also:
-
position
int position() -
skip
void skip(int length)
-