All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sdsu.io.ASCIIInputStream

java.lang.Object
   |
   +----java.io.InputStream
           |
           +----java.io.FilterInputStream
                   |
                   +----sdsu.io.ASCIIInputStream

public class ASCIIInputStream
extends FilterInputStream
implements DataInput
This class provides a way of getting interpreted ASCII input from a stream. The standard Java library doesn't provide any way of reading things like integers from standard input. This functionality is nice to have for interactive programs.

Version:
1.1 12 Sept 1997
Author:
Andrew Scherpbier (andrew@sdsu.edu)

Constructor Index

 o ASCIIInputStream(InputStream)
Creates a new ASCIIInputStream.

Method Index

 o bad()
Do not use. Deprecated.
 o eof()
Determines if stream is has reach end of file.
 o flushLine()
Causes the next I/O operation to start at the beginning of the next input line.
 o hadEof()
Determines if reach end of file in a previous read.
 o read(byte[])
Reads data into an array of bytes.
 o read(byte[], int, int)
Reads data into an array of bytes.
 o readBoolean()
Reads an ASCII boolean value.
 o readByte()
Reads a single byte.
 o readChar()
Read an ASCII character and convert it into the internal char format.
 o readDouble()
Reads an ASCII decimal floating point number.
 o readFloat()
Reads an ASCII decimal floating point number.
 o readFully(byte[])
Reads bytes, blocking until all bytes are read.
 o readFully(byte[], int, int)
Reads bytes, blocking until all bytes are read.
 o readInt()
Reads an ASCII decimal integer.
 o readLine()
Reads in a line that has been terminated by a \n, \r, \r\n or EOF.
 o readLong()
Reads an ASCII decimal long.
 o readShort()
Reads an ASCII decimal short.
 o readUnsignedByte()
Reads a single unsigned byte.
 o readUnsignedShort()
Reads an ASCII decimal unsigned short.
 o readUTF()
Does nothing.
 o readWord()
Reads a word.
 o skipBytes(int)
Skips bytes, block until all bytes are skipped.

Constructors

 o ASCIIInputStream
 public ASCIIInputStream(InputStream stream)
Creates a new ASCIIInputStream.

Parameters:
stream - the input stream

Methods

 o bad
 public boolean bad()
Note: bad() is deprecated.

Do not use. This method no longer does anything. Always returns false.

 o hadEof
 public boolean hadEof() throws IOException
Determines if reach end of file in a previous read. This differs from eof() in in that eof() will indicate end of file if only white space remains. This function only indicates if you actually reached end of file an a prevoius read. If only whitespace remains and you use readInt (readDouble, etc.) an exception will be thrown. Use this method to detect end of file only if direct access to the white space between tokens is important to your program and you handle the case of a file ending in white space properly.

Returns:
true if end of file was reached.
See Also:
eof
 o eof
 public boolean eof() throws IOException
Determines if stream is has reach end of file. Consumes white space up to next token. If your program needs that white space between tokens use hadEof() instead. eof() is the prefered way to detect end of file.

Returns:
true if end of file was reached or if only white space remained in the stream.
See Also:
hadEof
 o read
 public int read(byte b[]) throws IOException
Reads data into an array of bytes. This method blocks until some input is available.

Parameters:
b - the buffer into which the data is read.
Returns:
the actual number of bytes read. -1 is returned when the end of the stream is reached. (In this case, the eof() member will return true.)
Throws: IOException
If an I/O error has occurred.
Overrides:
read in class FilterInputStream
 o read
 public int read(byte b[],
                 int off,
                 int len) throws IOException
Reads data into an array of bytes. This method blocks until some input is available.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data
len - the maximum number of bytes read
Returns:
the actual number of bytes read. -1 is returned when the end of the stream is reached. (In this case, the eof() member will return true.)
Throws: IOException
If an I/O error has occurred.
Overrides:
read in class FilterInputStream
 o readFully
 public void readFully(byte b[]) throws IOException
Reads bytes, blocking until all bytes are read. If EOF is reached, the eof() member will return true.

Parameters:
b - the buffer into which the data is read
Throws: IOException
If an I/O error has occurred.
 o readFully
 public void readFully(byte b[],
                       int off,
                       int len) throws IOException
Reads bytes, blocking until all bytes are read. If EOF is reached, the eof() member will return true.

Parameters:
b - the buffer into which the data is read
off - the start offset of the data
len - the maximum number of bytes read
Throws: IOException
If an I/O error has occurred.
 o skipBytes
 public int skipBytes(int n) throws IOException
Skips bytes, block until all bytes are skipped.

Parameters:
n - the number of bytes to be skipped
Returns:
the actual number of bytes skipped.
Throws: IOException
If an I/O error has occurred.
 o readBoolean
 public boolean readBoolean() throws IOException
Reads an ASCII boolean value. It reads a word and determines if it represents true or false. Possible values are: true and false. The comparison is case insensitive. The eof() method will return true after this method has attempted to read beyond the end of file.

Returns:
the boolean.
Throws: IOException
If an I/O error has occurred.
Throws: NumberFormatException
If the next token in the input stream is not a valid boolean.
 o readByte
 public byte readByte() throws IOException
Reads a single byte. The eof() method will return true after this method has attempted to read beyond the end of file.

Returns:
the byte.
Throws: IOException
If an I/O error has occurred.
 o readUnsignedByte
 public int readUnsignedByte() throws IOException
Reads a single unsigned byte. This is virually the same as readChar(), except that the return value is an int.

Returns:
an int representing the unsigned byte.
Throws: IOException
If an I/O error has occurred.
See Also:
readChar
 o readShort
 public short readShort() throws IOException
Reads an ASCII decimal short. Shorts can be preceded by optional whitespace. whitespace is defined as SPACE, TAB, CR, or NL. The eof() method will return true after this method has attempted to read beyond the end of file.

Returns:
the short.
Throws: IOException
If an I/O error has occurred.
Throws: NumberFormatException
If next token is not a valid short. This is a runtime exception, so the compiler does not force you to catch it.
See Also:
ASCIIInputStream@readInt
 o readUnsignedShort
 public int readUnsignedShort() throws IOException
Reads an ASCII decimal unsigned short. Unsigned shorts can be preceded by optional whitespace. whitespace is defined as SPACE, TAB, CR, or NL.

Returns:
an int representing the unsigned short.
Throws: IOException
If an I/O error has occurred.
Throws: NumberFormatException
If next token is not a valid short. This is a runtime exception, so the compiler does not force you to catch it.
See Also:
ASCIIInputStream@readInt
 o readChar
 public char readChar() throws IOException
Read an ASCII character and convert it into the internal char format. The eof() method will return true after this method has attempted to read beyond the end of file.

Returns:
the character.
Throws: IOException
If an I/O error occurred.
 o readInt
 public int readInt() throws IOException
Reads an ASCII decimal integer. Integers can be preceded by optional whitespace. whitespace is defined as SPACE, TAB, CR, or NL. The eof() method will return true after this method has attempted to read beyond the end of file.

Returns:
the integer.
Throws: IOException
If an I/O error has occurred.
Throws: NumberFormatException
If the next token in the input stream is not a valid int. This is a runtime exception, so the compiler does not force you to catch it.
 o readLong
 public long readLong() throws IOException
Reads an ASCII decimal long. Longs can be preceded by optional whitespace. whitespace is defined as SPACE, TAB, CR, or NL. The eof() method will return true after this method has attempted to read beyond the end of file.

Returns:
the long.
Throws: IOException
If an I/O error has occurred.
Throws: NumberFormatException
If the next token in the input stream is not a valid long. This is a runtime exception, so the compiler does not force you to catch it.
 o readFloat
 public float readFloat() throws IOException
Reads an ASCII decimal floating point number. A floating point number is defined as follows: Floats can be preceded by optional whitespace. whitespace is defined as SPACE, TAB, CR, or NL.

Returns:
the float.
Throws: IOException
If an I/O error has occurred.
Throws: NumberFormatException
If the next token in the input stream is not a valid float format. Note NumberFormatException is a runtime exception.
 o readDouble
 public double readDouble() throws IOException
Reads an ASCII decimal floating point number. A floating point number is defined as follows: Doubles can be preceded by optional whitespace. whitespace is defined as SPACE, TAB, CR, or NL.

Returns:
the double.
Throws: IOException
If an I/O error has occurred.
Throws: NumberFormatException
If the next token in the input stream is not a valid double. This is a runtime exception, so the compiler does not force you to catch it.
 o readLine
 public String readLine() throws IOException
Reads in a line that has been terminated by a \n, \r, \r\n or EOF. The eof() method will return true if the read attempted to go beyond the end of file. The terminating line characters will not be part of the String that is returned.

Returns:
a String copy of the line or null if nothing more could be read.
Throws: IOException
If an I/O error has occurred.
 o readUTF
 public String readUTF() throws IOException
Does nothing. Do not use.

 o readWord
 public String readWord() throws IOException
Reads a word. A word is a string of characters deliminated by whitespace or EOF. A word can be preceded by optional whitespace characters. Whitespace is defined as SPACE, TAB, CR, or NL.

Returns:
the word or null if EOF reached.
Throws: IOException
If an I/O error has occurred.
 o flushLine
 public void flushLine() throws IOException
Causes the next I/O operation to start at the beginning of the next input line. Lines are delimited by either cr, cr lf, or lf.

Throws: IOException
If an I/O error has occurred.

All Packages  Class Hierarchy  This Package  Previous  Next  Index