public class BitInputStream
extends java.lang.Object
implements java.io.Closeable
| Modifier and Type | Field and Description |
|---|---|
private long |
bitsCached |
private int |
bitsCachedSize |
private java.nio.ByteOrder |
byteOrder |
private java.io.InputStream |
in |
private static long[] |
MASKS |
private static int |
MAXIMUM_CACHE_SIZE |
| Constructor and Description |
|---|
BitInputStream(java.io.InputStream in,
java.nio.ByteOrder byteOrder)
Constructor taking an InputStream and its bit arrangement.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearBitCache()
Clears the cache of bits that have been read from the
underlying stream but not yet provided via
readBits(int). |
void |
close() |
private boolean |
ensureCache(int count)
Fills the cache up to 56 bits
|
private long |
processBitsGreater57(int count) |
long |
readBits(int count)
Returns at most 63 bits read from the underlying stream.
|
private static final int MAXIMUM_CACHE_SIZE
private static final long[] MASKS
private final java.io.InputStream in
private final java.nio.ByteOrder byteOrder
private long bitsCached
private int bitsCachedSize
public BitInputStream(java.io.InputStream in,
java.nio.ByteOrder byteOrder)
in - the InputStreambyteOrder - the bit arrangement across byte boundaries,
either BIG_ENDIAN (aaaaabbb bb000000) or LITTLE_ENDIAN (bbbaaaaa 000000bb)public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionpublic void clearBitCache()
readBits(int).public long readBits(int count)
throws java.io.IOException
count - the number of bits to read, must be a positive
number not bigger than 63.java.io.IOException - on errorprivate long processBitsGreater57(int count)
throws java.io.IOException
java.io.IOExceptionprivate boolean ensureCache(int count)
throws java.io.IOException
count - java.io.IOException