public final class BitSource
extends java.lang.Object
This provides an easy abstraction to read bits at a time from a sequence of bytes, where the number of bits read is not often a multiple of 8.
This class is thread-safe but not reentrant -- unless the caller modifies the bytes array it passed in, in which case all bets are off.
Modifier and Type | Field and Description |
---|---|
private int |
bitOffset |
private int |
byteOffset |
private byte[] |
bytes |
Constructor and Description |
---|
BitSource(byte[] bytes) |
Modifier and Type | Method and Description |
---|---|
int |
available() |
int |
getBitOffset() |
int |
getByteOffset() |
int |
readBits(int numBits) |
private final byte[] bytes
private int byteOffset
private int bitOffset
public BitSource(byte[] bytes)
bytes
- bytes from which this will read bits. Bits will be read from the first byte first.
Bits are read within a byte from most-significant to least-significant bit.public int getBitOffset()
readBits(int)
.public int getByteOffset()
readBits(int)
.public int readBits(int numBits)
numBits
- number of bits to readjava.lang.IllegalArgumentException
- if numBits isn't in [1,32] or more than is availablepublic int available()