Package com.helger.commons.io.stream
Class BitOutputStream
java.lang.Object
com.helger.commons.io.stream.NonBlockingBitOutputStream
com.helger.commons.io.stream.BitOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
The BitOutputStream 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.
For a non-blocking version see
For a non-blocking version see
NonBlockingBitOutputStream.- Author:
- Andreas Jakl, Philip Helger
-
Constructor Summary
ConstructorsConstructorDescriptionBitOutputStream(OutputStream aOS, ByteOrder aByteOrder) Create a new bit output stream based on an existing Java OutputStream. -
Method Summary
Methods inherited from class com.helger.commons.io.stream.NonBlockingBitOutputStream
getByteOrder, toString, writeBits
-
Constructor Details
-
BitOutputStream
Create a new bit output stream based on an existing Java OutputStream.- Parameters:
aOS- the output stream this class should use. May not benull.aByteOrder- The non-nullbyte order to use.
-
-
Method Details
-
writeBit
Write a single bit to the stream. It will only be flushed to the underlying OutputStream when a byte has been completed or when flush() manually.- Overrides:
writeBitin classNonBlockingBitOutputStream- Parameters:
aBit- 1 if the bit should be set, 0 if not- Throws:
IOException- In case writing to the output stream failed
-
flush
Write the current cache to the stream and reset the buffer.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classNonBlockingBitOutputStream- Throws:
IOException- In case writing to the output stream failed
-
close
public void close()Flush the data and close the underlying output stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classNonBlockingBitOutputStream
-