All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class cs1.SafeInput

java.lang.Object
   |
   +----cs1.SafeInput

public class SafeInput
extends Object
Provides line buffered input that can be used either interactively or from a file. In interactive mode (using a non-null prompt file), one item is read per line. In "batch" mode (prompt = null), lines may contain several elements. Note that getLine retrieves the rest of the current line. In non-interactive mode, tokens will be skipped to try to find one of the desired kind. For example if you getInt() when the next input token is not a legal int, tokens will be skipped looking for an int. Failure will come at the end of the file, of course.

Sources: SafeInput.java


Constructor Index

 o SafeInput(PrintStream, InputStream)
Create a new inputter.
 o SafeInput(PrintWriter, Reader)
Create a new inputter.

Method Index

 o getDouble()
Get a double from the next location in the input.
 o getFloat()
Get a float from the next location in the input.
 o getInt()
Get an int from the next location in the input.
 o getLine()
Get the remainder of the current line buffer as input.
 o getLong()
Get a long from the next location in the input.
 o getWord()
Get a word from the next location in the input.
 o setDelimiters(String)
Set the delimiters that are used to separate tokens.

Constructors

 o SafeInput
 public SafeInput(PrintStream prompt,
                  InputStream in)
Create a new inputter. The PrintStream is used to prompt the user. Data is read from the InputFlie. If the input stream is a file, then the print stream used for prompting should be null.

Parameters:
prompt - A print stream used for prompting interactively. If null, no prompting will be done.
in - The input stream to be read.
 o SafeInput
 public SafeInput(PrintWriter prompt,
                  Reader in)
Create a new inputter. The PrintWriter is used to prompt the user. Data is read from the Reader. If the input stream is a file, then the print stream used for prompting should be null.

Parameters:
prompt - A PrintWriter used for prompting interactively. If null, no prompting will be done.
in - The input stream to be read.

Methods

 o getInt
 public int getInt()
Get an int from the next location in the input. When used interactively the user will be continuously prompted until a valid int is entered.

 o getFloat
 public float getFloat()
Get a float from the next location in the input. When used interactively the user will be continuously prompted until a valid float is entered.

 o getDouble
 public double getDouble()
Get a double from the next location in the input. When used interactively the user will be continuously prompted until a valid double is entered.

 o getLong
 public long getLong()
Get a long from the next location in the input. When used interactively the user will be continuously prompted until a valid long is entered.

 o getWord
 public String getWord()
Get a word from the next location in the input. In interactive mode, a new line will be read first.

 o getLine
 public String getLine()
Get the remainder of the current line buffer as input. In interactive mode, a fresh line will be read entirely.

 o setDelimiters
 public String setDelimiters(String newDelimiters)
Set the delimiters that are used to separate tokens. The default set is space and tab only.

Parameters:
newDelimiters - the new set of delimiting chars in a String.
Returns:
the original set of delimiters.

All Packages  Class Hierarchy  This Package  Previous  Next  Index