|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object src.BitOutputStream
public class BitOutputStream
The BitOutputStream allows writing individual bits to a general Java OutputStream. This class is able to write a single bit to a stream (even though a byte has to be filled until the data is flushed to the underlying output stream). It is also able to write Serializable objects.
The code is based on the following reference:
http://www.developer.nokia.com/Community/Wiki/Bit_Input/Output_Stream_utility_classes_for_efficient_data_transfer
The original author is Andreas Jakl. The code has been modified to include support for partial bytes at the end of the stream and to allow writing of serializable objects.
Constructor Summary | |
---|---|
BitOutputStream(java.io.OutputStream out)
Creates a BitOutputStream that writes bits to the specified OutputStream . |
|
BitOutputStream(java.lang.String name)
Creates a BitOutputStream stream that writes bits to the file with the given name. |
Method Summary | |
---|---|
void |
close()
Flushes the data and closes the underlying output stream. |
void |
writeBit(int bit)
Writes a single bit to the stream. |
void |
writeObject(java.lang.Object obj)
Writes an object to this stream. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BitOutputStream(java.io.OutputStream out) throws java.io.IOException
BitOutputStream
that writes bits to the specified OutputStream
.
out
- the output stream to write to
java.io.IOException
- - if an I/O error occurs while writing stream header
java.lang.SecurityException
- - if untrusted subclass illegally overrides security-sensitive methods
java.lang.NullPointerException
- - if out
is null
public BitOutputStream(java.lang.String name) throws java.io.IOException
BitOutputStream
stream that writes bits to the file with the given name.
name
- the name of the file to write the bits to
java.io.FileNotFoundException
- if the file does not exist, is a directory
rather than a regular file, or for some other reason cannot be
opened for reading
java.io.IOException
Method Detail |
---|
public void writeBit(int bit) throws java.io.IOException
OutputStream
when a byte has been completed (or when this stream is closed).
bit
- the next bit to write (either 1 or 0)
java.io.IOException
- if an I/O error occurspublic void writeObject(java.lang.Object obj) throws java.io.IOException
obj
- the object to be written to this stream
java.io.IOException
- if an I/O error occurspublic void close() throws java.io.IOException
java.io.IOException
- if an I/O error occurs
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |