Package eu.bandm.tools.util
Class BitOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
eu.bandm.tools.util.BitOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Output Stream which allows to write single bits sequentially.
Bits are written left aligned.
Explicit calls to write bytes and primitce types of multiple bytes
cause the bit buffer to be flushed. A file can grow like this:
0 1000 0001 | <= write((byte)0x81);
0 1000 0001
1 101. .... | <= write(true); write(false);write(true);
0 1000 0001
1 101. ....
2 0000 0001
3 0000 0010 | <= write((int)258));
-
Field Summary
Fields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidShifts the bits written to the bufferbufto be left aligned, writes the resulting byte and clears the buffer.voidclose()Closes the output stream after flushing the bit buffer..voidflush()Flushes the output stream after flushing the bit buffer.voidwrite(byte[] b) Writes bytes to the output after flushing the bit buffer.voidwrite(byte[] b, int off, int len) Writes bytes to the output after flushing the bit buffervoidwrite(int b) Writes one integer to the output after flushing the bit buffer.final voidwriteBit(boolean b) Write a boolean value as a bit value.voidwriteBit(int b) Appends a bit value at the lowest position in the buffer.Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
BitOutputStream
Only constructed. Sets the target of the write operations.
-
-
Method Details
-
close
Closes the output stream after flushing the bit buffer..- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException- See Also:
-
flush
Flushes the output stream after flushing the bit buffer.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classFilterOutputStream- Throws:
IOException- See Also:
-
write
Writes bytes to the output after flushing the bit buffer.- Overrides:
writein classFilterOutputStream- Throws:
IOException- See Also:
-
write
Writes bytes to the output after flushing the bit buffer- Overrides:
writein classFilterOutputStream- Throws:
IOException- See Also:
-
write
Writes one integer to the output after flushing the bit buffer.- Overrides:
writein classFilterOutputStream- Throws:
IOException- See Also:
-
byteAlign
Shifts the bits written to the bufferbufto be left aligned, writes the resulting byte and clears the buffer.- Throws:
IOException
-
writeBit
Write a boolean value as a bit value.- Throws:
IOException
-
writeBit
Appends a bit value at the lowest position in the buffer. If the buffer is full, flush it as inbyteAlign().- Throws:
IOException
-