|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.io.OutputStream
assignment4.BitOutputStream
public class BitOutputStream
Write bits-at-a-time where the number of bits is between 1 and 32.
Client programs must call flush or
close when finished writing or not all bits will be written.
This class is intended to be used with BitInputStream to
facilitate reading and writing data in a bits-at-a-time manner.
Updated for version 2.0 to extend java.io.OutputStream
Any exceptions generated are rethrown as RuntimeException objects
so client code does not have to catch or rethrow them.
| Constructor Summary | |
|---|---|
BitOutputStream(java.io.OutputStream out)
Create a stream that writes-through to the OutputStream object
passed as a parameter. |
|
BitOutputStream(java.lang.String filename)
Construct a bit-at-a-time output stream with specified file name. |
|
| Method Summary | |
|---|---|
void |
close()
Releases system resources associated with file and flushes bits not yet written. |
void |
flush()
Flushes bits not yet written, must be called by client programs if close isn't called. |
void |
write(int b)
Required by OutputStream subclasses, write the low 8-bits to the underlying outputstream |
void |
writeBits(int howManyBits,
int value)
Write specified number of bits from value to a file. |
| Methods inherited from class java.io.OutputStream |
|---|
write, write |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BitOutputStream(java.io.OutputStream out)
OutputStream object
passed as a parameter.
out - is the output stream to which bits are writtenpublic BitOutputStream(java.lang.String filename)
filename - is the name of the file being written
java.lang.RuntimeException - if opening file fails for either FileNotFound
or for Security exceptoins| Method Detail |
|---|
public void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic void flush()
close isn't called.
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.lang.RuntimeException - if there's a problem writing bitspublic void close()
close in interface java.io.Closeableclose in class java.io.OutputStreamjava.lang.RuntimeException - if close fails
public void writeBits(int howManyBits,
int value)
howManyBits - is number of bits to write (1-32)value - is source of bits, rightmost bits are written
java.lang.RuntimeException - if there's an I/O problem writing bits
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||