|
||||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.OutputStream java.io.FilterOutputStream java.io.PrintStream 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 0s to make the total number of bits a multiple of 8.
Field Summary | |
---|---|
static int |
BYTE_SIZE
|
static boolean |
DEBUG
|
static char |
EOF
|
Fields inherited from class java.io.FilterOutputStream |
---|
out |
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 |
hasSeenEOF()
Returns true if this output stream has ever written an EOF character; students should not call this method. |
boolean |
inBitMode()
Returns whether this stream is in real 'bit mode', writing a bit to the file for each call to writeBit. |
void |
print(char c)
Prints the given character to this output stream. |
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 |
setEOFEncoding(java.lang.String eofEncoding)
Sets this bit output stream to use the given pattern of bits as its encoding for the end of a file (EOF); students should not call this method. |
static java.lang.String |
toPrintable(char ch)
Converts the given character into a format that prints well on the screen. |
void |
write(int b)
Writes the given byte to output. |
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.PrintStream |
---|
append, append, append, checkError, clearError, format, format, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write |
Methods inherited from class java.io.FilterOutputStream |
---|
write |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final boolean DEBUG
public static final int BYTE_SIZE
public static final char EOF
Constructor Detail |
---|
public BitOutputStream(java.io.OutputStream output)
output
- the target output stream to write.
BitOutputStream.BitIOException
- 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.
BitOutputStream.BitIOException
- if the file cannot be opened for writing.Method Detail |
---|
public static java.lang.String toPrintable(char ch)
ch
- the character to convert, such as '\n'
public void close()
close
in interface java.io.Closeable
close
in class java.io.PrintStream
public void flush()
flush
in interface java.io.Flushable
flush
in class java.io.PrintStream
public boolean hasSeenEOF()
public boolean inBitMode()
public void setBitMode(boolean bitMode)
bitMode
- true to use bit mode, false to use character mode.public void setEOFEncoding(java.lang.String eofEncoding)
eofEncoding
- the EOF encoding to usepublic void write(int b)
write
in class java.io.PrintStream
b
- the byte value to write.
BitOutputStream.BitIOException
- if unable to write to the underlying output streampublic void print(char c)
print
in class java.io.PrintStream
c
- The character to print.public void writeBit(int bit)
bit
- the bit value to write.
java.lang.IllegalArgumentException
- if bit is not 0 or 1public void writeBits(java.lang.String bits)
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'.public void writeBytes(java.lang.String bytes)
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'.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 |