tio
Class ReadInput

java.lang.Object
  |
  +--tio.ReadInput

public class ReadInput
extends java.lang.Object

The class ReadInput contains methods that allow for simple input of numbers, strings and characters from a text stream.


Constructor Summary
ReadInput(java.io.InputStream input)
          Constructs a ReadInput object for reading from any InputStream.
ReadInput(java.io.Reader input)
          Constructs a ReadInput object for reading from any Reader object.
ReadInput(java.lang.String filename)
          Constructs a ReadInput object for reading from a file.
 
Method Summary
 boolean hasMoreElements()
          Check to see if there are any non-white space characters left in the input.
 int readChar()
          Read the next character.
 int readCharNonwhite()
          Read the next nonwhite character.
 double readDouble()
          Attempt to interpret the next white space delimited input characters as a double.
 float readFloat()
          Attempt to interpret the next white space delimited input characters as a float.
 int readInt()
          Attempt to interpret the next white space delimited input characters as an int.
 java.lang.String readLine()
          Read the next complete input line up to the newline character.
 java.lang.String readLineNonwhite()
          Read the next line that contains at least one, nonwhite character.
 long readLong()
          Attempt to interpret the next white space delimited input characters as a long.
 java.lang.String readWord()
          Read the next white space delimited string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadInput

public ReadInput(java.io.Reader input)
Constructs a ReadInput object for reading from any Reader object.
Parameters:
input - the Reader text stream to read from.

ReadInput

public ReadInput(java.lang.String filename)
Constructs a ReadInput object for reading from a file.
Parameters:
filename - the name of the file from which to read.
Throws:
FileNotFoundException - if the file can't be opened.

ReadInput

public ReadInput(java.io.InputStream input)
Constructs a ReadInput object for reading from any InputStream.
Parameters:
input - the InputStream to read from.
Method Detail

hasMoreElements

public boolean hasMoreElements()
Check to see if there are any non-white space characters left in the input. If used to terminate reading with readLine(), any trailing blank lines will be ignored. To read trailing blank lines, do not use hasMoreElements() and instead read with readLine() until an EOFException is thrown.
Returns:
true if the input contains more non-white space characters and false otherwise.

readChar

public int readChar()
Read the next character. White space is not skipped.
Returns:
the int value of the next character.

readDouble

public double readDouble()
Attempt to interpret the next white space delimited input characters as a double.
Returns:
the double value of the next, white-space delimited input string.
Throws:
java.lang.NumberFormatException - if the next input string does not contain a parsable double.

readFloat

public float readFloat()
Attempt to interpret the next white space delimited input characters as a float.
Returns:
the float value of the next, white-space delimited input string.
Throws:
java.lang.NumberFormatException - if the next input string does not contain a parsable float.

readInt

public int readInt()
Attempt to interpret the next white space delimited input characters as an int.
Returns:
the int value of the next, white-space delimited input string.
Throws:
java.lang.NumberFormatException - if the next input string does not contain a parsable int.

readLine

public java.lang.String readLine()
Read the next complete input line up to the newline character. The terminating newline character is read and discarded. It is not part of the return string. If the previous read was an attempt to read a number that generated a NumberFormatException, readLine() will return the input line including the input characters that caused the exception. This can be used to try and recover from failure to read numeric input.
Returns:
the next input line as a String.

readLong

public long readLong()
Attempt to interpret the next white space delimited input characters as a long.
Returns:
the long value of the next, white-space delimited input string.
Throws:
java.lang.NumberFormatException - if the next input string does not contain a parsable long.

readWord

public java.lang.String readWord()
Read the next white space delimited string.
Returns:
the next, white-space delimited input string.

readLineNonwhite

public java.lang.String readLineNonwhite()
Read the next line that contains at least one, nonwhite character.
Returns:
the next line that is not all whitespace characters.

readCharNonwhite

public int readCharNonwhite()
Read the next nonwhite character.
Returns:
the int value of the next nonwhite character.