|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.OutputStream BitOutputStream
public class BitOutputStream
The BitOutputStream and BitInputStream classes provide the ability to write and read individual bits to a file in a compact form. One minor limitation of this approach is that the resulting file will always have a number of bits that is a multiple of 8. In effect, whatever bits are output to the file are padded at the end with 0's to make the total number of bits a multiple of 8.
Field Summary | |
---|---|
static int |
BYTE_SIZE
|
static int |
EOF
|
Constructor Summary | |
---|---|
BitOutputStream(java.io.OutputStream output)
Creates a BitOutputStream to send output to the stream in 'bit mode'. |
|
BitOutputStream(java.io.OutputStream output,
boolean bitMode)
Creates a BitOutputStream to send output to the stream in the given mode. |
Method Summary | |
---|---|
void |
close()
Closes this output stream for writing and flushes any data to be written. |
protected void |
finalize()
Runs when the object is garbage collected / program shuts down. |
void |
flush()
Flushes the buffer. |
boolean |
inBitMode()
Returns whether this stream is in real 'bit mode', writing a bit to the file for each call to writeBit. |
void |
setBitMode(boolean bitMode)
Sets whether this stream is in real 'bit mode', writing a bit to the file for each 0 or 1 written in writeBit (as described under inBitMode). |
void |
write(int b)
|
void |
writeBit(int bit)
Writes given bit to output. |
void |
writeBits(java.lang.String bits)
Writes every bit in the given string of 0s and 1s. |
void |
writeBytes(java.lang.String bytes)
Writes every character in the given string of 0s and 1s as a byte. |
Methods inherited from class java.io.OutputStream |
---|
write, write |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int BYTE_SIZE
public static final int EOF
Constructor Detail |
---|
public BitOutputStream(java.io.OutputStream output)
output
- the target output stream to write.
java.lang.RuntimeException
- if the file cannot be opened for writing.public BitOutputStream(java.io.OutputStream output, boolean bitMode)
output
- the target output stream to write.bitMode
- true to write bits at a time; false to write ASCII
characters (bytes) at a time for debugging.
java.lang.RuntimeException
- if the file cannot be opened for writing.Method Detail |
---|
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in class java.io.OutputStream
java.io.IOException
- if the file cannot be closed.public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
- if the bits cannot be written.public boolean inBitMode()
public void setBitMode(boolean bitMode)
bitMode
- true to use bit mode, false to use character mode.public void write(int b) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void writeBit(int bit) throws java.io.IOException
bit
- the bit value to write.
java.lang.IllegalArgumentException
- if bit is not 0 or 1
java.io.IOException
- if the bit cannot be written.public void writeBits(java.lang.String bits) throws java.io.IOException
bits
- A string entirely of 0s and 1s, such as "01001100110".
java.lang.IllegalArgumentException
- if the string contains any characters
other than '0' or '1'.
java.io.IOException
public void writeBytes(java.lang.String bytes) throws java.io.IOException
bytes
- A string entirely of 0s and 1s, such as "01001100110".
java.lang.IllegalArgumentException
- if the string contains any characters
other than '0' or '1'.
java.io.IOException
protected void finalize()
finalize
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |