public class BitShiftedOutputStream extends FilterOutputStream
write(int). Due to implementation reasons the
amount of bits should be between 1 and 32, inclusive. Also note that you can
not use the OutputStream.write(byte[]) or
OutputStream.write(byte[], int, int) methods because they will
truncate your value to the lowest eight bits which is of course only a
problem if you intend to write values larger than eight bits.out| Constructor and Description |
|---|
BitShiftedOutputStream(OutputStream outputStream,
int valueSize)
Creates a new bit-shifted output stream that writes
valueSize bits per value. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
flush()
Flushes all unwritten data to the underlying output stream.
|
void |
flush(int fillBit)
Flushes this output stream, writing all unwritten values to the
underlying output stream.
|
void |
write(int value) |
void |
writePadding(int numberOfBits)
Writes the specified number of zero-bits to this stream.
|
void |
writePadding(int numberOfBits,
int fillBit)
Writes the specified number of bits to the stream.
|
write, writepublic BitShiftedOutputStream(OutputStream outputStream, int valueSize) throws IllegalArgumentException
valueSize bits per value.outputStream - The underlying output streamvalueSize - The number of bits to write with one write(int)
instructionIllegalArgumentException - if valueSize is not in the range of 1 to 32,
inclusivepublic void write(int value)
throws IOException
write in class FilterOutputStreamIOExceptionFilterOutputStream.write(int)public void writePadding(int numberOfBits)
throws IOException
numberOfBits - The number of zero-bits to writeIOException - if an I/O error occurspublic void writePadding(int numberOfBits,
int fillBit)
throws IOException
fillBit.numberOfBits - The number of padding bits to writefillBit - Contains at the lowest bit position the padding bit to writeIOException - if an I/O error occurspublic void flush()
throws IOException
This is a convenience method for flush(0x00) which
will zero-pad the unused bits in the last byte.
flush in interface Flushableflush in class FilterOutputStreamIOExceptionFilterOutputStream.flush()public void flush(int fillBit)
throws IOException
fillBit - The lowest bit of this value will determine what the unused
space in a byte is filled withIOException - if an I/O error occurspublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class FilterOutputStreamIOExceptionFilterOutputStream.close()Copyright © 2026. All rights reserved.