public final class BinaryIn extends java.lang.Object
The binary input stream can be from standard input, a filename, a URL name, a Socket, or an InputStream.
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 BinaryIn with calls to In; otherwise unexpected behavior will result.
Constructor and Description |
---|
BinaryIn()
Create a binary input stream from standard input.
|
BinaryIn(java.io.InputStream is)
Create a binary input stream from an InputStream.
|
BinaryIn(java.net.Socket socket)
Create a binary input stream from a socket.
|
BinaryIn(java.lang.String s)
Create a binary input stream from a filename or URL name.
|
BinaryIn(java.net.URL url)
Create a binary input stream from a URL.
|
Modifier and Type | Method and Description |
---|---|
boolean |
exists()
Does the binary input stream exist?
|
boolean |
isEmpty()
Returns true if the binary input stream is empty.
|
static void |
main(java.lang.String[] args)
Test client.
|
boolean |
readBoolean()
Read the next bit of data from the binary input stream and return as a boolean.
|
byte |
readByte()
Read the next 8 bits from the binary input stream and
return as an 8-bit byte.
|
char |
readChar()
Read the next 8 bits from the binary input stream and return as an 8-bit char.
|
char |
readChar(int r)
Read the next r bits from the binary input stream and return as an r-bit character.
|
double |
readDouble()
Read the next 64 bits from the binary input stream and return as a 64-bit double.
|
float |
readFloat()
Read the next 32 bits from standard input and return as a 32-bit float.
|
int |
readInt()
Read the next 32 bits from the binary input stream and
return as a 32-bit int.
|
int |
readInt(int r)
Read the next r bits from the binary input stream return as an r-bit int.
|
long |
readLong()
Read the next 64 bits from the binary input stream
and return as a 64-bit long.
|
short |
readShort()
Read the next 16 bits from the binary input stream and return as a 16-bit short.
|
java.lang.String |
readString()
Read the remaining bytes of data from the binary input stream and return as a string.
|
public BinaryIn()
public BinaryIn(java.io.InputStream is)
public BinaryIn(java.net.Socket socket)
public BinaryIn(java.net.URL url)
public BinaryIn(java.lang.String s)
public boolean exists()
public boolean isEmpty()
public boolean readBoolean()
java.lang.RuntimeException
- if the input stream is emptypublic char readChar()
java.lang.RuntimeException
- if there are fewer than 8 bits available.public char readChar(int r)
r
- number of bits to read.java.lang.RuntimeException
- if there are fewer than r bits available.public java.lang.String readString()
java.lang.RuntimeException
- if the input stream is empty or if the number of bits
available is not a multiple of 8 (byte-aligned)public short readShort()
java.lang.RuntimeException
- if there are fewer than 16 bits available.public int readInt()
java.lang.RuntimeException
- if there are fewer than 32 bits availablepublic int readInt(int r)
r
- number of bits to read.java.lang.RuntimeException
- if there are fewer than r bits available on standard inputpublic long readLong()
java.lang.RuntimeException
- if there are fewer than 64 bits availablepublic double readDouble()
java.lang.RuntimeException
- if there are fewer than 64 bits availablepublic float readFloat()
java.lang.RuntimeException
- if there are fewer than 32 bits
available on standard inputpublic byte readByte()
java.lang.RuntimeException
- if there are fewer than 8 bits available.public static void main(java.lang.String[] args)