All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class rebelsky.io.SimpleReader

java.lang.Object
   |
   +----rebelsky.io.SimpleReader

public class SimpleReader
extends Object
A simple input system for beginning programmers. Permits reading of basic data types without delving into the workings of the various Java libraries. Throws exceptions when errors occur. Most exceptions are from the java.io library and include FileNotFoundException, EOFException, and IOException. Some methods may also throw java.lang.NumberFormatException.

Warning! This code has not yet been thoroughly tested.

Copyright (c) 1998 Samuel A. Rebelsky. All rights reserved.

Version:
1.0 of February 1998
Author:
Samuel A. Rebelsky

Constructor Index

o SimpleReader()
Create a new object to read from standard input.
o SimpleReader(String)
Create a new object to read from an input file.

Method Index

o close()
Close the input.
o eoln()
See if we're at the end of the line.
o peek()
Look at the next character in the buffer.
o readChar()
Read the next character (including whitespace) from the given input.
o readDouble()
Read a double from the given input.
o readInt()
Read an integer from the given input.
o readLine()
Read one line from the given input and return that line without any carriage return or other line-terminating character.
o readLong()
Read a long integer from the given input.
o readString()
Read the next nonempty string, skipping any intervening whitespace (including carriage returns).
o skipWhite()
Skip over any whitespace until we reach a non-whitespace character or the end of file.

Constructors

o SimpleReader
 public SimpleReader()
Create a new object to read from standard input.
pre: standard input has not been modified.
post: the object will read from standard input.

o SimpleReader
 public SimpleReader(String input_file) throws FileNotFoundException
Create a new object to read from an input file. Make sure to call close when you are done with an input file.
pre: the file exists.
post: the object will read from that file.

Throws: FileNotFoundException
when the file does not exist.

Methods

o close
 public void close() throws IOException
Close the input.
pre: the input has not yet been closed.
post: the input is closed.

Throws: IOException
when difficulty is encountered closing the input (e.g., if the input has already been closed).
o eoln
 public boolean eoln() throws EOFException, IOException
See if we're at the end of the line.
pre: (none)
post: if no input has been read, input may be read
post: returns true if we're currently at the end of the line

Throws: EOFException
when attempting to read beyojnd the end of the file.
Throws: IOException
when some other I/O error occurs.
o peek
 public char peek() throws EOFException, IOException
Look at the next character in the buffer.
pre: we haven't reached the end of the buffer.
post: the next character to be read is returned.
post: one line of input may be read.

Throws: EOFException
when attempting to read beyojnd the end of the file.
Throws: IOException
when some other I/O error occurs.
o readChar
 public char readChar() throws EOFException, IOException
Read the next character (including whitespace) from the given input. If you are at the end of the line, returns the end of line character.
pre: (none)
post: input may be read

Throws: EOFException
when attempting to read beyojnd the end of the file.
Throws: IOException
when some other I/O error occurs.
o readDouble
 public double readDouble() throws EOFException, IOException, NumberFormatException, NumberRangeException
Read a double from the given input. Skips any whitespace up to the double . If the next thing in the input is not a double sets the cursor at the beginning of that thing, but does not read beyond it and returns the default double.
pre: the next input characters are whitespace and those that make up an double.
post: the cursor is after those digits.

Throws: EOFException
when attempting to read beyond end of file.
Throws: IOException
when other I/O errors occur.
Throws: NumberFormatException
when the next stuff on input isn't a double.
Throws: NumberRangeException
when the value entered is outside the standard range. Currently unimplemented.
o readInt
 public int readInt() throws EOFException, IOException, NumberFormatException, NumberRangeException
Read an integer from the given input. Skips any whitespace up to the integer. If the next thing in the input is not an integer, sets the cursor at the beginning of that thing, but does not read beyond it and returns the default integer.
pre: the next input characters are whitespace and those that make up an integer (optional sign and some number of digits).
post: the cursor is after those digits.

Throws: EOFException
when attempting to read beyojnd the end of the file.
Throws: IOException
when some other I/O error occurs.
Throws: NumberFormatException
when the next thing on the input stream is not an integer.
Throws: NumberRangeException
when the value entered is outside the standard range. Currently unimplemented.
o readLong
 public long readLong() throws EOFException, IOException, NumberFormatException, NumberRangeException
Read a long integer from the given input. Skips any whitespace up to the integer. If the next thing in the input is not an integer, sets the cursor at the beginning of that thing, but does not read beyond it and returns the default integer.
pre: the next input characters are whitespace and those that make up an integer (optional sign and some number of digits).
post: the cursor is after those digits.

Throws: EOFException
when attempting to read beyojnd the end of the file.
Throws: IOException
when some other I/O error occurs.
Throws: NumberFormatException
when the next thing on the input stream is not an integer.
Throws: NumberRangeException
when the value entered is outside the standard range. Currently unimplemented.
o readLine
 public String readLine() throws EOFException, IOException
Read one line from the given input and return that line without any carriage return or other line-terminating character. If we're at the end of file, return the empty string.
pre: we haven't reached the end of the input.
post: the next line (or partial line, if we're already on a line) is returned.

Throws: EOFException
when attempting to read beyojnd the end of the file.
Throws: IOException
when some other I/O error occurs.
o readString
 public String readString() throws EOFException, IOException
Read the next nonempty string, skipping any intervening whitespace (including carriage returns).
pre: we have not yet read beyond the end of the input.
post: The next nonempty string is returned.

Throws: EOFException
when attempting to read beyojnd the end of the file.
Throws: IOException
when some other I/O error occurs.
o skipWhite
 public void skipWhite() throws IOException, EOFException
Skip over any whitespace until we reach a non-whitespace character or the end of file.
pre: none
post: the cursor is at the next non-whitespace character of we've reached the end of file.

Throws: EOFException
when attempting to read beyojnd the end of the file.
Throws: IOException
when some other I/O error occurs.

All Packages  Class Hierarchy  This Package  Previous  Next  Index