| java.lang.Object java.io.Reader java.io.BufferedReader java.io.LineNumberReader
LineNumberReader | public class LineNumberReader extends BufferedReader (Code) | | LineNumberReader is a buffered character input reader which counts line
numbers as data is being read. The line number starts at 0 and is incremented
any time '\r', '\n', or '\r\n' is read.
See Also: BufferedWriter |
Constructor Summary | |
public | LineNumberReader(Reader in) Constructs a new buffered LineNumberReader on the Reader in . | public | LineNumberReader(Reader in, int size) Constructs a new buffered LineNumberReader on the Reader in . |
Method Summary | |
public int | getLineNumber() Answers a int representing the current line number for this
LineNumberReader. | public void | mark(int readlimit) Set a Mark position in this LineNumberReader. | public int | read() Reads a single char from this LineNumberReader and returns the result as
an int. | public int | read(char[] buffer, int offset, int count) Reads at most count chars from this LineNumberReader and
stores them in char array buffer starting at offset
offset . | public String | readLine() Answers a String representing the next line of text
available in this LineNumberReader. | public void | reset() Reset this LineNumberReader to the last marked location. | public void | setLineNumber(int lineNumber) Sets the lineNumber of this LineNumberReader to the specified
lineNumber . | public long | skip(long count) Skips count number of chars in this LineNumberReader.
Subsequent read() 's will not return these chars unless
reset() is used. |
LineNumberReader | public LineNumberReader(Reader in)(Code) | | Constructs a new buffered LineNumberReader on the Reader in .
The default buffer size (8K) is allocated and all reads can now be
filtered through this LineNumberReader.
Parameters: in - the Reader to buffer reads on. |
LineNumberReader | public LineNumberReader(Reader in, int size)(Code) | | Constructs a new buffered LineNumberReader on the Reader in .
The buffer size is specified by the parameter size and all
reads can now be filtered through this LineNumberReader.
Parameters: in - the Reader to buffer reads on. Parameters: size - the size of buffer to allocate. |
getLineNumber | public int getLineNumber()(Code) | | Answers a int representing the current line number for this
LineNumberReader.
int the current line number. |
mark | public void mark(int readlimit) throws IOException(Code) | | Set a Mark position in this LineNumberReader. The parameter
readLimit indicates how many characters can be read before
a mark is invalidated. Sending reset() will reposition the reader back to
the marked position provided readLimit has not been
surpassed. The lineNumber associated with this marked position will also
be saved and restored when reset() is sent provided
readLimit has not been surpassed.
Parameters: readlimit - an int representing how many characters must be read beforeinvalidating the mark. throws: IOException - If an error occurs attempting mark this LineNumberReader. |
read | public int read() throws IOException(Code) | | Reads a single char from this LineNumberReader and returns the result as
an int. The low-order 2 bytes are returned or -1 of the end of reader was
encountered. This implementation returns a char from the target reader.
The line number count is incremented if a line terminator is encountered.
A line delimiter sequence is determined by '\r', '\n', or '\r\n'. In this
method, the sequence is always translated into '\n'.
int The char read or -1 if end of reader. throws: IOException - If the reader is already closed or another IOExceptionoccurs. |
read | public int read(char[] buffer, int offset, int count) throws IOException(Code) | | Reads at most count chars from this LineNumberReader and
stores them in char array buffer starting at offset
offset . Answer the number of chars actually read or -1 if
no chars were read and end of reader was encountered. This implementation
reads chars from the target stream. The line number count is incremented
if a line terminator is encountered. A line delimiter sequence is
determined by '\r', '\n', or '\r\n'. In this method, the sequence is
always translated into '\n'.
Parameters: buffer - the char array in which to store the read chars. Parameters: offset - the offset in buffer to store the read chars. Parameters: count - the maximum number of chars to store in buffer . the number of chars actually read or -1 if end of reader. throws: IOException - If the reader is already closed or another IOExceptionoccurs. |
readLine | public String readLine() throws IOException(Code) | | Answers a String representing the next line of text
available in this LineNumberReader. A line is represented by 0 or more
characters followed by '\n' , '\r' ,
"\n\r" or end of stream. The String does
not include the newline sequence.
String the contents of the line or null if no characters wereread before end of stream. throws: IOException - If the LineNumberReader is already closed or some other IOerror occurs. |
reset | public void reset() throws IOException(Code) | | Reset this LineNumberReader to the last marked location. If the
readlimit has been passed or no mark has
been set, throw IOException. This implementation resets the target
reader. It also resets the line count to what is was when this reader was
marked.
throws: IOException - If the reader is already closed or another IOExceptionoccurs. |
setLineNumber | public void setLineNumber(int lineNumber)(Code) | | Sets the lineNumber of this LineNumberReader to the specified
lineNumber . Note that this may have side effects on the
line number associated with the last marked position.
Parameters: lineNumber - the new lineNumber value. |
skip | public long skip(long count) throws IOException(Code) | | Skips count number of chars in this LineNumberReader.
Subsequent read() 's will not return these chars unless
reset() is used. This implementation skips
count number of chars in the target stream and increments
the lineNumber count as chars are skipped.
Parameters: count - the number of chars to skip. the number of chars actually skipped. throws: IOException - If the reader is already closed or another IOExceptionoccurs. |
|
|