public class LineIterator extends Object implements Iterator<String>, Closeable
This class change the contract of hasNext() method by
throwing RuntimeIOException on IOException.
Decorators should override format(String) method.
This class is not threadsafe.
PropertiesSubstitutor| Constructor and Description |
|---|
LineIterator(Reader reader) |
LineIterator(Reader reader,
PropertiesSubstitutor substitutor) |
LineIterator(Reader reader,
PropertiesSubstitutor substitutor,
boolean trimLines)
Constructs iterator.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected String |
format(String line)
Applies additional formatting to the line read.
|
String |
getLineAt(int n)
Returns specified line or null if EOF occured.
|
boolean |
hasNext() |
String |
next()
Returns the next avalable line in a reader.
|
void |
remove() |
int |
skip(int n)
Skips N lines.
|
public LineIterator(Reader reader)
public LineIterator(Reader reader, PropertiesSubstitutor substitutor)
public LineIterator(Reader reader, PropertiesSubstitutor substitutor, boolean trimLines)
reader - reader to iterate.substitutor - substitutor to use to expand properties or null to disable substitution.trimLines - true if the returned lines should be trimmed.public boolean hasNext()
throws RuntimeIOException
hasNext in interface Iterator<String>next()RuntimeIOException - if IO error occurs.protected String format(String line)
May be overriden by decorators.
line - line of text, nulls allowed.public String next() throws RuntimeIOException, NoSuchElementException
next in interface Iterator<String>RuntimeIOException - if IO error occurs.NoSuchElementException - if has no more elements.public int skip(int n)
n - number of lines to skip.public String getLineAt(int n)
n - line number relative to the current line in the input. n>=0public void remove()
throws UnsupportedOperationException
remove in interface Iterator<String>UnsupportedOperationExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2006-2012. All Rights Reserved.