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
-
SafeInput(PrintStream, InputStream)
- Create a new inputter.
-
SafeInput(PrintWriter, Reader)
- Create a new inputter.
-
getDouble()
- Get a double from the next location in the input.
-
getFloat()
- Get a float from the next location in the input.
-
getInt()
- Get an int from the next location in the input.
-
getLine()
- Get the remainder of the current line buffer as input.
-
getLong()
- Get a long from the next location in the input.
-
getWord()
- Get a word from the next location in the input.
-
setDelimiters(String)
- Set the delimiters that are used to separate tokens.
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.
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.
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.
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.
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.
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.
getWord
public String getWord()
- Get a word from the next location in the input. In interactive mode,
a new line will be read first.
getLine
public String getLine()
- Get the remainder of the current line buffer as input. In interactive
mode, a fresh line will be read entirely.
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