Class BitInputStream
java.lang.Object
org.apache.commons.compress.utils.BitInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
Reads bits from an InputStream.
- Since:
- 1.10
- This class is not thread-safe
-
Constructor Summary
ConstructorsConstructorDescriptionBitInputStream(InputStream in, ByteOrder byteOrder) Constructor taking an InputStream and its bit arrangement. -
Method Summary
Modifier and TypeMethodDescriptionvoidDrops bits until the next bits will be read from a byte boundary.longReturns an estimate of the number of bits that can be read from this input stream without blocking by the next invocation of a method for this input stream.intReturns the number of bits that can be read from this input stream without reading from the underlying input stream at all.voidClears the cache of bits that have been read from the underlying stream but not yet provided viareadBits(int).voidclose()longReturns the number of bytes read from the underlying stream.longreadBits(int count) Returns at most 63 bits read from the underlying stream.
-
Constructor Details
-
BitInputStream
Constructor taking an InputStream and its bit arrangement.- Parameters:
in- the InputStreambyteOrder- the bit arrangement across byte boundaries, either BIG_ENDIAN (aaaaabbb bb000000) or LITTLE_ENDIAN (bbbaaaaa 000000bb)
-
-
Method Details
-
alignWithByteBoundary
Drops bits until the next bits will be read from a byte boundary.- Since:
- 1.16
-
bitsAvailable
Returns an estimate of the number of bits that can be read from this input stream without blocking by the next invocation of a method for this input stream.- Returns:
- estimate of the number of bits that can be read without blocking
- Throws:
IOException- if the underlying stream throws one when calling available- Since:
- 1.16
-
bitsCached
Returns the number of bits that can be read from this input stream without reading from the underlying input stream at all.- Returns:
- estimate of the number of bits that can be read without reading from the underlying stream
- Since:
- 1.16
-
clearBitCache
Clears the cache of bits that have been read from the underlying stream but not yet provided viareadBits(int). -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getBytesRead
Returns the number of bytes read from the underlying stream.This includes the bytes read to fill the current cache and not read as bits so far.
- Returns:
- the number of bytes read from the underlying stream
- Since:
- 1.17
-
readBits
Returns at most 63 bits read from the underlying stream.- Parameters:
count- the number of bits to read, must be a positive number not bigger than 63.- Returns:
- the bits concatenated as a long using the stream's byte order. -1 if the end of the underlying stream has been reached before reading the requested number of bits
- Throws:
IOException- on error
-