public class LookaheadReader
extends java.lang.Object
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.
Constructor | Description |
---|---|
LookaheadReader(java.io.Reader reader) |
Creates a LookaheadReader from a source reader.
|
Modifier and Type | Method | Description |
---|---|---|
java.lang.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.
|
java.lang.String |
nextLine() |
Reads and returns a line from the source reader.
|
public LookaheadReader(java.io.Reader reader)
reader
- a reader whose contents will be returned by the
LookaheadReaderpublic java.lang.String getCurrentLine()
nextLine
was not
called before.nextLine()
java.util.NoSuchElementException
- if nextLine
was not yet calledpublic java.lang.String nextLine() throws java.io.IOException
java.io.IOException
- on error while reading the source readerjava.util.NoSuchElementException
- if hasNextLine()
is falsepublic boolean hasNextLine() throws java.io.IOException
java.io.IOException
- on error while reading the source readerpublic int getLineNumber()
getCurrentLine()
, or 0 before the first
call to nextLine
. The first line has line number 1.