Public Member Functions | |
LineIterator (final Reader reader) throws IllegalArgumentException | |
boolean | hasNext () |
Object | next () |
String | nextLine () |
void | close () |
void | remove () |
Static Public Member Functions | |
static void | closeQuietly (LineIterator iterator) |
Protected Member Functions | |
boolean | isValidLine (String line) |
An Iterator over the lines in a Reader
.
LineIterator
holds a reference to an open Reader
. When you have finished with the iterator you should close the reader to free internal resources. This can be done by closing the reader directly, or by calling the close() or closeQuietly(LineIterator) method on the iterator.
The recommended usage pattern is:
LineIterator it = FileUtils.lineIterator(file, "UTF-8"); try { while (it.hasNext()) { String line = it.nextLine(); /// do something with line } } finally { LineIterator.closeQuietly(iterator); }
com.skytree.epub.LineIterator.LineIterator | ( | final Reader | reader | ) | throws IllegalArgumentException |
Constructs an iterator of the lines for a Reader
.
reader | the Reader to read from, not null |
IllegalArgumentException | if the reader is null |
void com.skytree.epub.LineIterator.close | ( | ) |
Closes the underlying Reader
quietly. This method is useful if you only want to process the first few lines of a larger file. If you do not close the iterator then the Reader
remains open. This method can safely be called multiple times.
|
static |
Closes the iterator, handling null and ignoring exceptions.
iterator | the iterator to close |
boolean com.skytree.epub.LineIterator.hasNext | ( | ) |
Indicates whether the Reader
has more lines. If there is an IOException
then close() will be called on this instance.
true
if the Reader has more lines IllegalStateException | if an IO exception occurs |
|
protected |
Overridable method to validate each line that is returned.
line | the line that is to be validated |
Object com.skytree.epub.LineIterator.next | ( | ) |
Returns the next line in the wrapped Reader
.
NoSuchElementException | if there is no line to return |
String com.skytree.epub.LineIterator.nextLine | ( | ) |
Returns the next line in the wrapped Reader
.
NoSuchElementException | if there is no line to return |
void com.skytree.epub.LineIterator.remove | ( | ) |
Unsupported.
UnsupportedOperationException | always |