Package net.sf.statcvs.util
Class LookaheadReader
- java.lang.Object
-
- net.sf.statcvs.util.LookaheadReader
-
public class LookaheadReader extends java.lang.Object
Wraps a
Reader
for line-by-line access. This works likeIterator
: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.
- Version:
- $Id: LookaheadReader.java,v 1.4 2008/04/02 11:22:15 benoitx Exp $
- Author:
- Richard Cyganiak (richard@cyganiak.de)
-
-
Constructor Summary
Constructors Constructor Description LookaheadReader(java.io.Reader reader)
Creates a LookaheadReader from a source reader.
-
Method Summary
All Methods Instance Methods Concrete Methods 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 bygetCurrentLine()
, or 0 before the first call tonextLine
.boolean
hasNextLine()
Checks if more lines are available for reading.java.lang.String
nextLine()
Reads and returns a line from the source reader.
-
-
-
Method Detail
-
getCurrentLine
public java.lang.String getCurrentLine()
Returns the current line without reading a line from the source reader. Will throw an exception ifnextLine
was not called before.- Returns:
- The line returned by the previous call to
nextLine()
- Throws:
java.util.NoSuchElementException
- ifnextLine
was not yet called
-
nextLine
public java.lang.String nextLine() throws java.io.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.- Returns:
- The next line of the source reader
- Throws:
java.io.IOException
- on error while reading the source readerjava.util.NoSuchElementException
- ifhasNextLine()
is false
-
hasNextLine
public boolean hasNextLine() throws java.io.IOException
Checks if more lines are available for reading.- Returns:
- true if at least one more line can be read
- Throws:
java.io.IOException
- on error while reading the source reader
-
getLineNumber
public int getLineNumber()
Returns the number of the line that would be returned bygetCurrentLine()
, or 0 before the first call tonextLine
. The first line has line number 1.- Returns:
- the current line number
-
-