net.sf.statcvs.util
Class LookaheadReader
public class LookaheadReader
Wraps a
Reader
for line-by-line access.
This works like
Iterator
:
hasNextLine()
returns true if another line can be read;
nextLine
reads
the next line and returns it. Additionally,
getCurrentLine()
can be used to access multiple times the line returned by
nextLine().
At construction time,
getCurrentLine() is undefined.
nextLine() must be called once to read the first line.
$Id: LookaheadReader.java,v 1.4 2008/04/02 11:22:15 benoitx Exp $- Richard Cyganiak (richard@cyganiak.de)
LookaheadReader(Reader reader) - Creates a LookaheadReader from a source reader.
|
String | getCurrentLine() - Returns the current line without reading a line from the source
reader.
|
int | getLineNumber() - Returns the number of the line that would be returned by
getCurrentLine() , or 0 before the first
call to nextLine .
|
boolean | hasNextLine() - Checks if more lines are available for reading.
|
String | nextLine() - Reads and returns a line from the source reader.
|
LookaheadReader
public LookaheadReader(Reader reader)
Creates a LookaheadReader from a source reader.
reader
- a reader whose contents will be returned by the
LookaheadReader
getCurrentLine
public String getCurrentLine()
Returns the current line without reading a line from the source
reader. Will throw an exception if
nextLine
was not
called before.
- The line returned by the previous call to
nextLine()
getLineNumber
public int getLineNumber()
Returns the number of the line that would be returned by
getCurrentLine()
, or 0 before the first
call to
nextLine
. The first line has line number 1.
hasNextLine
public boolean hasNextLine()
throws IOException
Checks if more lines are available for reading.
- true if at least one more line can be read
nextLine
public String nextLine()
throws IOException
Reads and returns a line from the source reader. The result of
this call will be the new current line. Will throw an exception
if trying to read from after the end of the source reader.
- The next line of the source reader