public class NonBlockingBitOutputStream extends Object implements Closeable, Flushable
NonBlockingBitOutputStream allows writing individual bits to a
general Java OutputStream. Like the various Stream-classes from Java, the
BitOutputStream has to be created based on another OutputStream. This class
is able to write a single bit to a stream (even though a byte has to be
filled until the data is flushed to the underlying output stream). It is also
able to write an integer value to the stream using the specified number of
bits.BitOutputStream| Constructor and Description |
|---|
NonBlockingBitOutputStream(OutputStream aOS,
ByteOrder aByteOrder)
Create a new bit output stream based on an existing Java OutputStream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Flush the data and close the underlying output stream.
|
void |
flush()
Write the current cache to the stream and reset the buffer.
|
ByteOrder |
getByteOrder() |
String |
toString() |
void |
writeBit(int aBit)
Write a single bit to the stream.
|
void |
writeBits(int aValue,
int nNumBits)
Write the specified number of bits from the int value to the stream.
|
public NonBlockingBitOutputStream(@Nonnull OutputStream aOS, @Nonnull ByteOrder aByteOrder)
aOS - the output stream this class should use. May not be
null.aByteOrder - The non-null byte order to use.public void writeBit(int aBit)
throws IOException
aBit - 1 if the bit should be set, 0 if notIOException - In case writing to the output stream failedpublic void writeBits(int aValue,
@Nonnegative
int nNumBits)
throws IOException
aValue - the int containing the bits that should be written to the stream.nNumBits - how many bits of the integer should be written to the stream.IOException - In case writing to the output stream failedpublic void flush()
throws IOException
flush in interface FlushableIOException - In case writing to the output stream failedpublic void close()
close in interface Closeableclose in interface AutoCloseableCopyright © 2014–2019 Philip Helger. All rights reserved.