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
public class BitOutputStream extends NonBlockingBitOutputStream
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 seeNonBlockingBitOutputStream.- Author:
- Andreas Jakl, Philip Helger
-
-
Constructor Summary
Constructors Constructor Description BitOutputStream(OutputStream aOS, ByteOrder aByteOrder)Create a new bit output stream based on an existing Java OutputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Flush the data and close the underlying output stream.voidflush()Write the current cache to the stream and reset the buffer.voidwriteBit(int aBit)Write a single bit to the stream.-
Methods inherited from class com.helger.commons.io.stream.NonBlockingBitOutputStream
getByteOrder, toString, writeBits
-
-
-
-
Constructor Detail
-
BitOutputStream
public BitOutputStream(@Nonnull OutputStream aOS, @Nonnull ByteOrder aByteOrder)
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 Detail
-
writeBit
public void writeBit(int aBit) throws IOExceptionWrite 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
public void flush() throws IOExceptionWrite 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
-
-