public final class BinaryStdOut extends Object
The client must flush() the output stream when finished writing bits.
The client should not intermixing calls to BinaryStdOut with calls to StdOut or System.out; otherwise unexpected behavior will result.
Modifier and Type | Method and Description |
---|---|
static void |
close()
Flush and close standard output.
|
static void |
flush()
Flush standard output, padding 0s if number of bits written so far
is not a multiple of 8.
|
static void |
main(String[] args)
Test client.
|
static void |
write(boolean x)
Write the specified bit to standard output.
|
static void |
write(byte x)
Write the 8-bit byte to standard output.
|
static void |
write(char x)
Write the 8-bit char to standard output.
|
static void |
write(char x,
int r)
Write the r-bit char to standard output.
|
static void |
write(double x)
Write the 64-bit double to standard output.
|
static void |
write(float x)
Write the 32-bit float to standard output.
|
static void |
write(int x)
Write the 32-bit int to standard output.
|
static void |
write(int x,
int r)
Write the r-bit int to standard output.
|
static void |
write(long x)
Write the 64-bit long to standard output.
|
static void |
write(short x)
Write the 16-bit int to standard output.
|
static void |
write(String s)
Write the string of 8-bit characters to standard output.
|
static void |
write(String s,
int r)
Write the String of r-bit characters to standard output.
|
public static void flush()
public static void close()
public static void write(boolean x)
x
- the boolean to write.public static void write(byte x)
x
- the byte to write.public static void write(int x)
x
- the int to write.public static 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 static void write(double x)
x
- the double to write.public static void write(long x)
x
- the long to write.public static void write(float x)
x
- the float to write.public static void write(short x)
x
- the short to write.public static void write(char x)
x
- the char to write.RuntimeException
- if x is not betwen 0 and 255.public static 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 static void write(String s)
s
- the String to write.RuntimeException
- if any character in the string is not
between 0 and 255.public static 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)