ObjectBinaryOut
public final class BinaryOut
Binary output. This class provides methods for converting primtive type variables (boolean, byte, char, int, long, float, and double) to sequences of bits and writing them to an output stream. The output stream can be standard output, a file, an OutputStream or a Socket. Uses big-endian (most-significant byte first).
The client must flush() the output stream when finished writing bits.
The client should not intermixing calls to BinaryOut with calls to Out; otherwise unexpected behavior will result.
| Constructor Summary | |
|---|---|
BinaryOut()
Create a binary output stream from standard output. |
|
BinaryOut(java.io.OutputStream os)
Create a binary output stream from an OutputStream. |
|
BinaryOut(java.net.Socket socket)
Create a binary output stream from a Socket. |
|
BinaryOut(String s)
Create a binary output stream from a filename. |
|
| Method Summary | |
|---|---|
void |
close()
Close and flush the binary output stream. |
void |
flush()
Flush the binary output stream, padding 0s if number of bits written so far is not a multiple of 8. |
static void |
main(String[] args)
Test client. |
void |
write(boolean x)
Write the specified bit to the binary output stream. |
void |
write(byte x)
Write the 8-bit byte to the binary output stream. |
void |
write(char x)
Write the 8-bit char to the binary output stream. |
void |
write(char x,
int r)
Write the r-bit char to the binary output stream. |
void |
write(double x)
Write the 64-bit double to the binary output stream. |
void |
write(float x)
Write the 32-bit float to the binary output stream. |
void |
write(int x)
Write the 32-bit int to the binary output stream. |
void |
write(int x,
int r)
Write the r-bit int to the binary output stream. |
void |
write(long x)
Write the 64-bit long to the binary output stream. |
void |
write(short x)
Write the 16-bit int to the binary output stream. |
void |
write(String s)
Write the string of 8-bit characters to the binary output stream. |
void |
write(String s,
int r)
Write the String of r-bit characters to the binary output stream. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BinaryOut(java.io.OutputStream os)
public BinaryOut()
public BinaryOut(String s)
public BinaryOut(java.net.Socket socket)
| Method Detail |
|---|
public void flush()
public void close()
public void write(boolean x)
x - the boolean to write.public void write(byte x)
x - the byte to write.public void write(int x)
x - the int to write.
public void write(int x,
int r)
x - the int to write.r - the number of relevant bits in the char.
RuntimeException - if r is not between 1 and 32.
RuntimeException - if x is not between 0 and 2r - 1.public void write(double x)
x - the double to write.public void write(long x)
x - the long to write.public void write(float x)
x - the float to write.public void write(short x)
x - the short to write.public void write(char x)
x - the char to write.
RuntimeException - if x is not betwen 0 and 255.
public void write(char x,
int r)
x - the char to write.r - the number of relevant bits in the char.
RuntimeException - if r is not between 1 and 16.
RuntimeException - if x is not between 0 and 2r - 1.public void write(String s)
s - the String to write.
RuntimeException - if any character in the string is not
between 0 and 255.
public void write(String s,
int r)
s - the String to write.r - the number of relevants bits in each character.
RuntimeException - if r is not between 1 and 16.
RuntimeException - if any character in the string is not
between 0 and 2r - 1.public static void main(String[] args)