java.io.LineNumberReader
java.io.BufferedReader
None
None
New as of JDK 1.1
The LineNumberReader class is a BufferedReader that keeps track of line numbers. The line number starts at 0 and is incremented each time an end-of-line character is encountered. LineNumberReader recognizes "\n", "\r", or "\r\n" as the end of a line. Regardless of the end-of-line character it reads, ReaderInputStream returns only "\n". The current line number is returned by getLineNumber().
The LineNumberReader class is the JDK 1.1 replacement for LineNumberInputStream. Not only does it correctly handle byte to character conversions (via Reader), it implements read(byte[], int, int) and skip() more efficiently than its predecessor.
public class java.io.LineNumberReader extends java.io.BufferedReader { // Constructors public LineNumberReader(Reader in); public LineNumberReader(Reader in, int sz); // Instance Methods public int getLineNumber(); public void mark(int readAheadLimit); public int read(); public int read(char[] cbuf, int off, int len); public String readLine(); public void reset(); public void setLineNumber(int lineNumber); public long skip(long n); }
The reader to use.
This constructor creates a LineNumberReader that gets its data from in and uses a default sized buffer. The default buffer size for BufferedReader is 8192 characters.
The reader to use.
The buffer size.
This constructor creates a LineNumberReader that gets its data from in and uses a buffer of the given size.
The current line number.
This method returns the current line number.
The maximum number of characters that can be read before the saved position becomes invalid.
If any kind of I/O error occurs.
BufferedReader.mark()
This method causes the LineNumberReader to remember its current position. A subsequent call to reset() causes the object to return to that saved position and thus reread a portion of the input.
The next character of data or -1 if the end of the stream is encountered.
If any kind of I/O error occurs.
BufferedReader.read()
This method reads a character of input from the underlying reader. If "\n", "\r", or "\r\n" is read from the stream, "\n" is returned. Otherwise the character read from the underlying BufferedReader is returned verbatim. The method blocks until it reads the character, the end of stream is encountered, or an exception is thrown.
An array of characters to be filled from the stream.
An offset into the array.
The number of characters to read.
The actual number of characters read or -1 if the end of the stream is encountered immediately.
If any kind of I/O error occurs.
BufferedReader.read(char[], int, int)
This method reads up to len characters of input into the given array starting at index off. This method, unlike read(), returns end-of-line characters exactly as they come from the underlying BufferedReader. The method blocks until data is available.
A String containing the line just read, or null if the end of the stream has been reached.
If any kind of I/O error occurs.
BufferedReader.readLine()
This method reads a line of text. Lines are terminated by "\n", "\r", or "\r\n". The line terminators are not returned with the line string.
If the reader is closed, mark() has not been called, or the saved position has been invalidated.
BufferedReader.reset()
This method sets the position of the reader to a position that was saved by a previous call to mark(). Subsequent characters read from this reader will begin from the saved position and continue normally. The method also restores the line number to its correct value for the mark location.
The new line number.
This method sets the current line number of the LineNumberReader. The method does not change the position of the reader.
The number of characters to skip.
The actual number of bytes skipped.
If any kind of I/O error occurs.
BufferedReader.skip()
This method skips n characters of input.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
close() |
BufferedReader |
equals(Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
markSupported() |
BufferedReader |
read(char[]) |
Reader |
ready() |
BufferedReader |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
BufferedReader, Reader, IOException, LineNumberInputStream
This HTML Help has been published using the chm2web software. |