structure5
Class ReadStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by structure5.ReadStream
All Implemented Interfaces:
java.io.Closeable

public class ReadStream
extends java.io.FilterInputStream

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 = new ReadStream();
      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  java.io.DataInputStream strm
          The underlying data stream.
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
ReadStream()
          Construct an empty ReadStream, obtaining info from System.in.
ReadStream(java.io.InputStream strm)
          Construct a ReadStream based on pre-existing input stream.
 
Method Summary
 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.
 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.
 java.lang.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.
 java.lang.String readString()
          Skip white space and read in the next non-whitespace word as a string.
 java.lang.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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

strm

protected java.io.DataInputStream strm
The underlying data stream.


atEOF

protected boolean atEOF
True iff we've seen the end-of-file


buffer

protected char[] buffer
The buffer to hold pushback characters


buffersize

protected int buffersize
The number of characters to be stored in buffer.


buffertop

protected int buffertop

absorbNL

protected boolean absorbNL
Whether or not accept the CR as part of previous newline.

Constructor Detail

ReadStream

public ReadStream()
Construct an empty ReadStream, obtaining info from System.in.

Postcondition:
constructs a pascal-like stream based on System.in

ReadStream

public ReadStream(java.io.InputStream strm)
Construct a ReadStream based on pre-existing input stream.

Parameters:
strm - The pre-existing input stream.
Precondition:
strm is a valid input stream
Postcondition:
constructs a pascal-like stream based on strm
Method Detail

eof

public boolean eof()
Determine if we've seen end-of-file.

Returns:
True if the next character to be read is EOF.
Precondition:
are we at the end-of-file?

getFirst

public char getFirst()
Read (but don't consume) next char in stream.

Returns:
The next character to be read.
Postcondition:
returns next character in stream, without consuming it

eoln

public boolean eoln()
Return true if the next character to be read is an end-of-line mark.

Returns:
True iff the next character is an end-of-line mark.
Postcondition:
returns true if next stream char is an eoln char

readln

public void readln()
Read characters up to and including the end-of-line mark.

Postcondition:
reads input stream until end-of-line (\r or \n)

skipWhite

public void skipWhite()
Consume all the white-space characters until EOF or other data.

Postcondition:
input pointer is at EOF, or nonwhitespace char

readString

public java.lang.String readString()
Skip white space and read in the next non-whitespace word as a string.

Returns:
The next word on the input.
Postcondition:
reads next word as a string

readBoolean

public boolean readBoolean()
Read the next word "true" or "false" as a boolean.

Returns:
The value true or false, depending on input.
Postcondition:
returns next boolean value read from input

readChar

public char readChar()
Read next character, whitespace or not. Fail on eof.

Returns:
The next character, or the value 0 indicating EOF.
Postcondition:
returns next character, or 0 for eof

pushbackChar

public void pushbackChar(char c)
Return character to input stream for reading at later time.

Parameters:
c - The character to push back onto input stream.
Postcondition:
pushes back character, possibly clearing EOF; if c == 0, does nothing

readDouble

public double readDouble()
Reads the next double value from input stream. Whitespace is skipped beforehand. CURRENTLY NOT WORKING.

Returns:
The next double found on input.
Postcondition:
reads in double value

readFloat

public float readFloat()
Read floating point value from input (Currently not working). Skips whitespace before reading.

Returns:
Next floating point number.
Postcondition:
reads floating point value and returns value

readFully

public void readFully(byte[] b)
               throws java.io.IOException
Read an array of bytes from input.

Parameters:
b - The array of bytes; holds result.
Throws:
java.io.IOException

readFully

public void readFully(byte[] b,
                      int off,
                      int len)
               throws java.io.IOException
Read input into byte array.

Parameters:
b - Target array of bytes.
off - Offset into byte array to start reading.
len - Number of bytes to be read.
Throws:
java.io.IOException

readShort

public short readShort()
Reads an integer from input stream.

Returns:
The integer read form input.
Postcondition:
reads a short integer from stream

readInt

public int readInt()
Reads an integer from input stream.

Returns:
The integer read form input.
Postcondition:
reads an integer from stream

readLong

public long readLong()
Read a (potentially long) input.

Returns:
The integer read from input.
Postcondition:
reads a long integer from stream

readLine

public java.lang.String readLine()
Read the remainder of line, including end-of-line mark.

Returns:
The string containing all the characters to end-of-line.
Postcondition:
reads remainder of line, returns as string

readUTF

public java.lang.String readUTF()
                         throws java.io.IOException
Read unicode from input.

Returns:
String version of UTF character.
Throws:
java.io.IOException