|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object pt.tumba.ngram.compression.BitOutput
public final class BitOutput
Writes to an underlying output stream a bit at a time. A bit is can be input
as a boolean, with true=1
and false=0
, or
as a number, in which case any non-zero input will be converted to
1
. If the number of bits written before closing the output
does not land on a byte boundary, the remaining fractional byte is
filled with 0
bits.
BitInput
Field Summary | |
---|---|
private int |
_nextBitIndex
The indexof the next bit to write into the next byte. |
private int |
_nextByte
Buffering for output. |
private java.io.OutputStream |
_out
Underlying output stream. |
Constructor Summary | |
---|---|
BitOutput(java.io.OutputStream out)
Construct a bit output from the specified output stream. |
Method Summary | |
---|---|
void |
close()
Closes underlying output stream after filling to a byte boundary with 0 bits. |
void |
flush()
Flushes the underlying output stream. |
private void |
reset()
Resets the bit buffer. |
void |
writeBit(boolean bit)
Writes the single specified bit to the underlying output stream, 1 for true and 0 for false . |
void |
writeBitFalse()
Writes a single false (0 ) bit. |
void |
writeBitTrue()
Writes a single true (1 ) bit. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private int _nextByte
private int _nextBitIndex
private final java.io.OutputStream _out
Constructor Detail |
---|
public BitOutput(java.io.OutputStream out)
out
- Underlying output stream.Method Detail |
---|
public void close() throws java.io.IOException
0
bits.
java.io.IOException
- If there is an I/O exception writing the next byte or closing the underlying output stream.public void flush() throws java.io.IOException
java.io.IOException
- If there is an exception flushing the underlying output stream.public void writeBit(boolean bit) throws java.io.IOException
1
for true
and 0
for false
.
bit
- Value to write.
java.io.IOException
- If there is an exception in the underlying output stream.public void writeBitTrue() throws java.io.IOException
true
(1
) bit.
java.io.IOException
- If there is an exception in the underlying output stream.public void writeBitFalse() throws java.io.IOException
false
(0
) bit.
java.io.IOException
- If there is an exception in the underlying output stream.private void reset()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |