public final class BinaryStdIn extends Object
All primitive types are assumed to be represented using their standard Java representations, in big-endian (most significant byte first) order.
The client should not intermix calls to BinaryStdIn with calls to StdIn or System.in; otherwise unexpected behavior will result.
Modifier and Type | Method and Description |
---|---|
static void |
close()
Close this input stream and release any associated system resources.
|
static boolean |
isEmpty()
Returns true if standard input is empty.
|
static void |
main(String[] args)
Test client.
|
static boolean |
readBoolean()
Read the next bit of data from standard input and return as a boolean.
|
static byte |
readByte()
Read the next 8 bits from standard input and return as an 8-bit byte.
|
static char |
readChar()
Read the next 8 bits from standard input and return as an 8-bit char.
|
static char |
readChar(int r)
Read the next r bits from standard input and return as an r-bit character.
|
static double |
readDouble()
Read the next 64 bits from standard input and return as a 64-bit double.
|
static float |
readFloat()
Read the next 32 bits from standard input and return as a 32-bit float.
|
static int |
readInt()
Read the next 32 bits from standard input and return as a 32-bit int.
|
static int |
readInt(int r)
Read the next r bits from standard input and return as an r-bit int.
|
static long |
readLong()
Read the next 64 bits from standard input and return as a 64-bit long.
|
static short |
readShort()
Read the next 16 bits from standard input and return as a 16-bit short.
|
static String |
readString()
Read the remaining bytes of data from standard input and return as a string.
|
public static void close()
public static boolean isEmpty()
public static boolean readBoolean()
RuntimeException
- if standard input is emptypublic static char readChar()
RuntimeException
- if there are fewer than 8 bits available on standard inputpublic static char readChar(int r)
r
- number of bits to read.RuntimeException
- if there are fewer than r bits available on standard inputRuntimeException
- unless 1 ≤ r ≤ 16public static String readString()
RuntimeException
- if standard input is empty or if the number of bits
available on standard input is not a multiple of 8 (byte-aligned)public static short readShort()
RuntimeException
- if there are fewer than 16 bits available on standard inputpublic static int readInt()
RuntimeException
- if there are fewer than 32 bits available on standard inputpublic static int readInt(int r)
r
- number of bits to read.RuntimeException
- if there are fewer than r bits available on standard inputRuntimeException
- unless 1 ≤ r ≤ 32public static long readLong()
RuntimeException
- if there are fewer than 64 bits available on standard inputpublic static double readDouble()
RuntimeException
- if there are fewer than 64 bits available on standard inputpublic static float readFloat()
RuntimeException
- if there are fewer than 32 bits available on standard inputpublic static byte readByte()
RuntimeException
- if there are fewer than 8 bits available on standard inputpublic static void main(String[] args)