Class java.io.TextInputStream
All Packages This Package Previous Next
Class java.io.TextInputStream
java.lang.Object
|
+----java.io.InputStream
|
+----java.io.FilterInputStream
|
+----java.io.TextInputStream
-
public class
TextInputStream
-
extends FilterInputStream
An input stream for reading text files. This class is useful for reading
a text file and breaking it up into Java strings. Each string will contain
one line of text, lines with only a line terminator will be represented
by zero length Java strings. At any time you can request the line number
of the file you are on, but invoking the currentLine() method.
NOTE: This class reads ASCII date into Unicode strings, if you wish
to read UTF (UNICODE Text Format) strings you should use DataInputStream
instead.
-
Version:
-
1.3, 02 Apr 1995
-
Author:
-
Chuck McManis
-
See Also:
-
String
-
atEOF
-
-
curBufferPos
-
-
inputBuffer
-
-
lineNumber
-
The current line number.
-
TextInputStream(InputStream, int)
-
Create a textInputStream with a specific buffer size.
-
TextInputStream(InputStream)
-
Creates a TextInputStream.
-
EOF()
-
-
available()
-
Returns the number of bytes that can be read, this is the sum of
what is in the buffer and what the stream returns.
-
currentLine()
-
Returns the current line number.
-
mark(int)
-
Set a mark on the InputStream, if that stream supports marks.
-
read()
-
read a byte - reads a single byte from the input stream and returns
-1 on end of file.
-
read(byte[])
-
read into a byte array.
-
readLine()
-
Read an ISO-Latin1 line of text from the input stream and return a
Java String.
-
reset()
-
Reposition the stream to the last marked position, restores the line
number to the number that existed when the mark was set.
-
skip(int)
-
Skip some number of bytes of input, note that this actually reads
the bytes that are skipped to keep track of the current line number.
lineNumber
protected int lineNumber
-
The current line number.
inputBuffer
protected byte inputBuffer[]
curBufferPos
protected int curBufferPos
atEOF
protected boolean atEOF
TextInputStream
public TextInputStream(InputStream in,
int bufSize)
-
Create a textInputStream with a specific buffer size.
TextInputStream
public TextInputStream(InputStream in)
-
Creates a TextInputStream.
-
Parameters:
-
in
-
the input stream
EOF
public boolean EOF()
readLine
public synchronized String readLine()
-
Read an ISO-Latin1 line of text from the input stream and return a
Java String.
The line terminator is stripped from the returned string. This
method recognizes , , and as the end of line
sequence. Note: it treats a sequence as two lines.
While this might be considered a bug, no current operating
system uses to terminate lines in text files.
@return null on end-of-file.
read
public synchronized int read()
-
read a byte - reads a single byte from the input stream and returns
-1 on end of file. Internally the line number is tracked by watching
for line terminator characters to go by.
-
Overrides:
-
read in class FilterInputStream
read
public synchronized int read(byte b[])
-
read into a byte array. This is augmented to manage the line number
state.
-
Overrides:
-
read in class FilterInputStream
currentLine
public int currentLine()
-
Returns the current line number.
skip
public int skip(int n)
-
Skip some number of bytes of input, note that this actually reads
the bytes that are skipped to keep track of the current line number.
-
Overrides:
-
skip in class FilterInputStream
available
public synchronized int available()
-
Returns the number of bytes that can be read, this is the sum of
what is in the buffer and what the stream returns.
-
Overrides:
-
available in class FilterInputStream
mark
public synchronized void mark(int readlimit)
-
Set a mark on the InputStream, if that stream supports marks. In
this class we will keep track of the current line number as well.
-
Overrides:
-
mark in class FilterInputStream
-
See Also:
-
FilterInputStream
reset
public synchronized void reset()
-
Reposition the stream to the last marked position, restores the line
number to the number that existed when the mark was set.
-
Overrides:
-
reset in class FilterInputStream
-
See Also:
-
FilterInputStream
All Packages This Package Previous Next