public final class BinaryOut extends java.lang.Object
The client must flush() the output stream when finished writing bits.
The client should not intermix calls to BinaryOut with calls to Out; otherwise unexpected behavior will result.
Constructor and Description |
---|
BinaryOut()
Create a binary output stream from standard output.
|
BinaryOut(java.io.OutputStream os)
Create a binary output stream from an OutputStream os.
|
BinaryOut(java.net.Socket socket)
Create a binary output stream from a Socket.
|
BinaryOut(java.lang.String s)
Create a binary output stream from a filename s.
|
Modifier and Type | Method and Description |
---|---|
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(java.lang.String[] args)
Test client.
|
void |
write(boolean x)
Write the bit specified by x to the binary output stream.
|
void |
write(byte x)
Write the 8-bit byte x to the binary output stream.
|
void |
write(char x)
Write the 8-bit char x to the binary output stream.
|
void |
write(char x,
int r)
Write the r-bit char x to the binary output stream.
|
void |
write(double x)
Write the 64-bit double x to the binary output stream.
|
void |
write(float x)
Write the 32-bit float x to the binary output stream.
|
void |
write(int x)
Write the 32-bit int x to the binary output stream.
|
void |
write(int x,
int r)
Write the r-bit int x to the binary output stream.
|
void |
write(long x)
Write the 64-bit long x to the binary output stream.
|
void |
write(short x)
Write the 16-bit int x to the binary output stream.
|
void |
write(java.lang.String s)
Write the string s of 8-bit characters to the binary output stream.
|
void |
write(java.lang.String s,
int r)
Write the String s of r-bit characters to the binary output stream.
|
public BinaryOut(java.io.OutputStream os)
public BinaryOut()
public BinaryOut(java.lang.String s)
public BinaryOut(java.net.Socket socket)
public void flush()
public void close()
public void write(boolean x)
public void write(byte x)
public void write(int x)
public void write(int x, int r)
java.lang.RuntimeException
- if r is not between 1 and 32.java.lang.RuntimeException
- if x is not between 0 and 2^r - 1.public void write(double x)
public void write(long x)
public void write(float x)
public void write(short x)
public void write(char x)
java.lang.RuntimeException
- if x is not betwen 0 and 255.public void write(char x, int r)
java.lang.RuntimeException
- if r is not between 1 and 16.java.lang.RuntimeException
- if x is not between 0 and 2^r - 1.public void write(java.lang.String s)
java.lang.RuntimeException
- if any character in the string is not
between 0 and 255.public void write(java.lang.String s, int r)
java.lang.RuntimeException
- if r is not between 1 and 16.java.lang.RuntimeException
- if any character in the string is not
between 0 and 2^r - 1.public static void main(java.lang.String[] args)