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);
}
| Modifier and Type | Field and Description |
|---|---|
| private final BufferedReader | bufferedReader
The reader that is being read. |
| private String | cachedLine
The current line. |
| private boolean | finished
A flag indicating if the iterator has been fully read. |
| Access | Constructor and Description |
|---|---|
| public | LineIterator(final Reader
the reader)Reader to read from, not nullConstructs an iterator of the lines for a |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public static void | closeQuietly(LineIterator
the iterator to close iterator)Closes the iterator, handling null and ignoring exceptions. |
| public boolean | Returns: true if the Reader has more linesImplements java. Reader has more lines.
|
| protected boolean | Returns: true if valid, false to remove from the iteratorthe line that is to be validated line)Overridable method to validate each line that is returned. |
| public Object | Returns: the next line from the inputImplements java. Reader.
|
| public String | |
| public void |
| bufferedReader | back to summary |
|---|---|
| private final BufferedReader bufferedReader The reader that is being read. | |
| cachedLine | back to summary |
|---|---|
| private String cachedLine The current line. | |
| finished | back to summary |
|---|---|
| private boolean finished A flag indicating if the iterator has been fully read. | |
| LineIterator | back to summary |
|---|---|
| public LineIterator(final Reader reader) throws IllegalArgumentException Constructs an iterator of the lines for a
| |
| close | back to summary |
|---|---|
| public void close() Closes the underlying | |
| closeQuietly | back to summary |
|---|---|
| public static void closeQuietly(LineIterator iterator) Closes the iterator, handling null and ignoring exceptions.
| |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Indicates whether the
| |
| isValidLine | back to summary |
|---|---|
| protected boolean isValidLine(String line) Overridable method to validate each line that is returned.
| |
| next | back to summary |
|---|---|
| public Object next() Implements java. Returns the next line in the wrapped
| |
| nextLine | back to summary |
|---|---|
| public String nextLine() Returns the next line in the wrapped
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides default java. Unsupported.
| |