The Crinch bits library provides a consistent and carefully considered abstraction for reading and writing data at bit level. In addition to this, an extremely powerful class for manipulating fixed-length bit sequences is provided that complements the available reader/writer implementations.
The backbone of the package consists of two interfaces and a concrete class, respectively:
BitReaderwhich is used to read bit sequences,
BitWriterwhich is used to write bit sequences and
BitVectorwhich stores, manipulates and casts bits sequences
See the Javadocs to find out more about the methods each class exposes.
The rest of the package mostly consists of concrete pairs of
ByteArrayBitWriterdirect bits to and from an array of bytes. Byte arrays are a convenient way for many applications to aggregate binary data.
IntArrayBitWriterdirect bits to and from an array of ints. Writing bits to ints should exhibit slightly better performance than writing to bytes. These implementations also have the advantage that bit sequences do not have end on a byte boundary.
OutputStreamBitWriterdirect bits to and from streams. Writing bits to ints should exhibit slightly better performance than writing to bytes. Applications looking to read bits directly from a file should use the much faster
FileChannelBitWriter* direct bits to and from a file.
NullBitWriterdirect bits nowhere and are useful for measuring the length of a bit sequence without storing the bits.
class is useful for reading bits from a specified file; different
modes are available with different memory/performance tradeoffs.
For developers looking to implement their own
BitWriter implementations, the
classes reduce the task to the implementation of a single method.
simplify the task still further in the common case where the bits are
being stored byte-by-byte.
See information about Crinch
* These classes are not available yet and will be included in a later release.