Class TextInputFile

java.lang.Object
  extended by TextInputFile

public class TextInputFile
extends Object


Field Summary
protected  boolean closed
          Set if the file has been closed.
protected static int EMPTY
          Constants and variables used by the input line buffer.
protected  boolean eofFlag
          The end-of-file flag
protected  BufferedReader f
          Stream used for reading input.
protected  String fileName
          The file name.
protected  String lineBuffer
           
(package private)  int lineBufferPtr
           
(package private)  int ungotChar
           
protected  boolean useStandardIO
          Indicator whether to write to standard output or a file.
 
Constructor Summary
TextInputFile()
          Contructor - TextInputFile to read from standard input.
TextInputFile(File file)
          Contructor - TextInputFile to read from a File.
TextInputFile(String fileName)
          Contructor - TextInputFile to read from file with specified name.
 
Method Summary
 void close()
          Close the file to further reading.
 boolean eof()
          Return whether there is an eof before the next token.
protected  void pushACharacter(char ch)
          Place the character in the unread position.
protected  char readACharacter()
          Read a single character from the file.
protected  char readACharacterThrowsEOF()
          Read a single character from the file.
protected  void readALineFromFile()
          Reads a line from the file.
protected  String readAToken()
          Reads in input from the keyboard buffer until it hits a whitespace, which indicates the end of a token.
 boolean readBoolean()
          Read a boolean from the file.
 byte readByte()
          Read an 8-bit integer (a "byte") from the file.
 char readChar()
          Read a single character from the file.
 double readDouble()
          Read a double precision floating point number (a "double") from the file.
 float readFloat()
          Read a floating point number (a "float") from the file.
 int readInt()
          Read a 32-bit integer (an "int") from the file.
 String readLine()
          Read a full line of text from the file.
 long readLong()
          Read a 64-bit integer (a "long") from the file.
 short readShort()
          Read a 16-bit integer (a "short") from the file.
 String readString()
          Read a whitespace delimited token from the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

closed

protected boolean closed
Set if the file has been closed.


EMPTY

protected static final int EMPTY
Constants and variables used by the input line buffer.

See Also:
Constant Field Values

eofFlag

protected boolean eofFlag
The end-of-file flag


f

protected BufferedReader f
Stream used for reading input.


fileName

protected String fileName
The file name.


lineBuffer

protected String lineBuffer

lineBufferPtr

int lineBufferPtr

ungotChar

int ungotChar

useStandardIO

protected boolean useStandardIO
Indicator whether to write to standard output or a file.

Constructor Detail

TextInputFile

public TextInputFile()
Contructor - TextInputFile to read from standard input.


TextInputFile

public TextInputFile(File file)
Contructor - TextInputFile to read from a File.

Parameters:
file - - File to be opened.

TextInputFile

public TextInputFile(String fileName)
Contructor - TextInputFile to read from file with specified name.

Parameters:
fileName - - Name of the file to be opened.
Method Detail

close

public void close()
Close the file to further reading.


eof

public boolean eof()
Return whether there is an eof before the next token.

Returns:
Whether there is an eof before the next token

pushACharacter

protected void pushACharacter(char ch)
Place the character in the unread position. The next time a character is read, this one will be returned.

Parameters:
ch - - The character to be pushed into the unread position.

readACharacter

protected char readACharacter()
Read a single character from the file. If we reach EOF before reading the character, display an error message and exit.

Returns:
The character read from the file.

readACharacterThrowsEOF

protected char readACharacterThrowsEOF()
                                throws EOFException
Read a single character from the file.

Returns:
The character read from the file.
Throws:
EOFException - - Thrown if attempt to read past EOF.

readALineFromFile

protected void readALineFromFile()
                          throws EOFException
Reads a line from the file.

Throws:
EOFException - - Thrown if attempt to read past EOF.

readAToken

protected String readAToken()
Reads in input from the keyboard buffer until it hits a whitespace, which indicates the end of a token.


readBoolean

public boolean readBoolean()
Read a boolean from the file. The actual text in the file must be either "true" or "false" although case is irrelvant.

Returns:
The boolean value read from the file.

readByte

public byte readByte()
Read an 8-bit integer (a "byte") from the file. The actual text in the file must be a number from -128 to 127.

Returns:
The byte value read from the file.

readChar

public char readChar()
Read a single character from the file. Note that this discards any whitespace. If you want to get every character on the line, use the readLine () method.

Returns:
The character read from the file.

readDouble

public double readDouble()
Read a double precision floating point number (a "double") from the file.

Returns:
The double value read from the file.

readFloat

public float readFloat()
Read a floating point number (a "float") from the file.

Returns:
The float value read from the file.

readInt

public int readInt()
Read a 32-bit integer (an "int") from the file. The actual text in the file must be a number from -2147483648 to 2147483647.

Returns:
The int value read from the file.

readLine

public String readLine()
Read a full line of text from the file.

Returns:
The line of text read from the file.

readLong

public long readLong()
Read a 64-bit integer (a "long") from the file.

Returns:
The long value read from the file.

readShort

public short readShort()
Read a 16-bit integer (a "short") from the file. The actual text in the file must be a number from -32768 to 32767.

Returns:
The short value read from the file.

readString

public String readString()
Read a whitespace delimited token from the file.

Returns:
The token read from the file.