Package eu.bandm.tools.util.files
Class BitOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
eu.bandm.tools.util.files.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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Shifts the bits written to the bufferbuf
to be left aligned, writes the resulting byte and clears the buffer.void
close()
Closes the output stream after flushing the bit buffer..void
flush()
Flushes the output stream after flushing the bit buffer.void
write
(byte[] b) Writes bytes to the output after flushing the bit buffer.void
write
(byte[] b, int off, int len) Writes bytes to the output after flushing the bit buffervoid
write
(int b) Writes one integer to the output after flushing the bit buffer.final void
writeBit
(boolean b) Write a boolean value as a bit value.void
writeBit
(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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterOutputStream
- Throws:
IOException
- See Also:
-
flush
Flushes the output stream after flushing the bit buffer.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classFilterOutputStream
- Throws:
IOException
- See Also:
-
write
Writes bytes to the output after flushing the bit buffer.- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
- See Also:
-
write
Writes bytes to the output after flushing the bit buffer- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
- See Also:
-
write
Writes one integer to the output after flushing the bit buffer.- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
- See Also:
-
byteAlign
Shifts the bits written to the bufferbuf
to 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
-