Class sdsu.io.ASCIIInputStream
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.
- Author:
- Andrew Scherpbier (andrew@sdsu.edu)
-
ASCIIInputStream(InputStream)
- Creates a new ASCIIInputStream.
-
bad()
- Determines if a previous ASCII I/O operation caused an error.
-
eof()
- Determines if a previous ASCII I/O operation caught End Of File.
-
flushLine()
- Causes the next I/O operation to start at the beginning of the next
input line.
-
read(byte[])
- Reads data into an array of bytes.
-
read(byte[], int, int)
- Reads data into an array of bytes.
-
readBoolean()
- Reads an ASCII boolean value.
-
readByte()
- Reads a single byte.
-
readChar()
- Read an ASCII character and convert it into the internal char
format.
-
readDouble()
- Reads an ASCII decimal floating point number.
-
readFloat()
- Reads an ASCII decimal floating point number.
-
readFully(byte[])
- Reads bytes, blocking until all bytes are read.
-
readFully(byte[], int, int)
- Reads bytes, blocking until all bytes are read.
-
readInt()
- Reads an ASCII decimal integer.
-
readLine()
- Reads in a line that has been terminated by a \n, \r,
\r\n or EOF.
-
readLong()
- Reads an ASCII decimal long.
-
readShort()
- Reads an ASCII decimal short.
-
readUnsignedByte()
- Reads a single unsigned byte.
-
readUnsignedShort()
- Reads an ASCII decimal unsigned short.
-
readUTF()
- Does nothing.
-
readWord()
- Reads a word.
-
skipBytes(int)
- Skips bytes, block until all bytes are skipped.
ASCIIInputStream
public ASCIIInputStream(InputStream stream)
- Creates a new ASCIIInputStream.
bad
public boolean bad()
- Determines if a previous ASCII I/O operation caused an error.
Errors can occur in the reading of numbers.
- Returns:
- true if there was an error.
- See Also:
- eof
eof
public boolean eof()
- Determines if a previous ASCII I/O operation caught End Of File.
- Returns:
- true if end of file was reached.
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
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
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.
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.
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.
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 for false are:
All other words are considered true.
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.
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.
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
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.
- See Also:
- ASCIIInputStream@readInt
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.
- See Also:
- ASCIIInputStream@readInt
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.
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.
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 or 0 when EOF was reached.
- Throws: IOException
- If an I/O error has occurred.
readFloat
public float readFloat() throws IOException
- Reads an ASCII decimal floating point number.
A floating point number is defined as follows:
- an optional '-' to make the number negative
- 0 or more digits
- an optional period follows by more digits
- an optional 'e' or 'E' to introduce the exponent
- an optional '-' to make the exponent negative
- digits making up the exponent
Floats can be preceded by optional whitespace.
whitespace is defined as SPACE, TAB, CR, or NL.
If an error on the format of the number is found, the
bad() member will return true.
- Returns:
- the float.
- Throws: IOException
- If an I/O error has occurred.
readDouble
public double readDouble() throws IOException
- Reads an ASCII decimal floating point number.
A floating point number is defined as follows:
- an optional '-' to make the number negative
- 0 or more digits
- an optional period follows by more digits
- an optional 'e' or 'E' to introduce the exponent
- an optional '-' to make the exponent negative
- digits making up the exponent
Doubles can be preceded by optional whitespace.
whitespace is defined as SPACE, TAB, CR, or NL.
If an error on the format of the number is found, the
bad() member will return true.
- Returns:
- the double.
- Throws: IOException
- If an I/O error has occurred.
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.
readUTF
public String readUTF() throws IOException
- Does nothing. Do not use.
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.
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