|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.InputStream | +--java.io.FilterInputStream | +--structure.ReadStream
A ReadStream provides reasonable access to the typewritten data on an input stream. Usually, a ReadStream is constructed with no parameters, causing the ReadStream to open access to System.in.
The access methods allow one to read from the stream, much as is done with Pascal.
Typical usage:
To read everything typed in System.in into a vector we could use the following:
public static void main(String[] argv){ ReadStream r = newReadStream()
; Vector buffer = new Vector(); while(!r.eof()
){ buffer.add(r.readString()
); } System.out.println(buffer); System.out.println(buffer.size()); } }
Field Summary | |
protected boolean |
absorbNL
Whether or not accept the CR as part of previous newline. |
protected boolean |
atEOF
True iff we've seen the end-of-file |
protected char[] |
buffer
The buffer to hold pushback characters |
protected int |
buffersize
The number of characters to be stored in buffer. |
protected int |
buffertop
|
protected DataInputStream |
strm
The underlying data stream. |
Fields inherited from class java.io.FilterInputStream |
in |
Fields inherited from class java.io.InputStream |
SKIP_BUFFER_SIZE, skipBuffer |
Constructor Summary | |
ReadStream()
Construct an empty ReadStream, obtaining info from System.in. |
|
ReadStream(InputStream strm)
Construct a ReadStream based on pre-existing input stream. |
Method Summary | |
private boolean |
acceptChar(char c)
|
private boolean |
acceptWord(String s)
|
boolean |
eof()
Determine if we've seen end-of-file. |
boolean |
eoln()
Return true if the next character to be read is an end-of-line mark. |
char |
getFirst()
Read (but don't consume) next char in stream. |
private static boolean |
isWhite(char c)
|
void |
pushbackChar(char c)
Return character to input stream for reading at later time. |
boolean |
readBoolean()
Read the next word "true" or "false" as a boolean. |
char |
readChar()
Read next character, whitespace or not. |
double |
readDouble()
Reads the next double value from input stream. |
float |
readFloat()
Read floating point value from input (Currently not working). |
void |
readFully(byte[] b)
Read an array of bytes from input. |
void |
readFully(byte[] b,
int off,
int len)
Read input into byte array. |
int |
readInt()
Reads an integer from input stream. |
String |
readLine()
Read the remainder of line, including end-of-line mark. |
void |
readln()
Read characters up to and including the end-of-line mark. |
long |
readLong()
Read a (potentially long) input. |
short |
readShort()
Reads an integer from input stream. |
String |
readString()
Skip white space and read in the next non-whitespace word as a string. |
String |
readUTF()
Read unicode from input. |
void |
skipWhite()
Consume all the white-space characters until EOF or other data. |
Methods inherited from class java.io.FilterInputStream |
available, close, mark, markSupported, read, read, read, reset, skip |
Methods inherited from class java.lang.Object |
|
Field Detail |
protected DataInputStream strm
protected boolean atEOF
protected char[] buffer
protected int buffersize
protected int buffertop
protected boolean absorbNL
Constructor Detail |
public ReadStream()
public ReadStream(InputStream strm)
strm
- The pre-existing input stream.Method Detail |
public boolean eof()
private static boolean isWhite(char c)
public char getFirst()
public boolean eoln()
public void readln()
public void skipWhite()
public String readString()
private boolean acceptChar(char c)
private boolean acceptWord(String s)
public boolean readBoolean()
public char readChar()
public void pushbackChar(char c)
c
- The character to push back onto input stream.public double readDouble()
public float readFloat()
public void readFully(byte[] b) throws IOException
b
- The array of bytes; holds result.public void readFully(byte[] b, int off, int len) throws IOException
b
- Target array of bytes.off
- Offset into byte array to start reading.len
- Number of bytes to be read.public short readShort()
public int readInt()
public long readLong()
public String readLine()
public String readUTF() throws IOException
|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |