public class TextFileIterator extends Object implements Iterator<String>
Splitter
.
E.g. in Groovy, you can use this iterator like this:
...
.split { exchange ->
String filename = exchange.getIn().getBody();
return new TextFileIterator(filename);
}
...
The intention of this class is to read long text files without loading the
whole file into memory. The largest portion of the file that is kept in
memory is an individual line as read by BufferedReader.readLine()
.Constructor and Description |
---|
TextFileIterator(String filename)
Creates an iterator for a given file name
|
TextFileIterator(String filename,
LineSplitterLogic lineSplitterLogic)
Creates an iterator for a given file name
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes any open resources and stops an active iteration
|
boolean |
hasNext() |
boolean |
isClosed() |
String |
next() |
void |
remove() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
public TextFileIterator(String filename) throws IOException
filename
- name of the file that should be readIOException
- If the file does not exist or could not be readpublic TextFileIterator(String filename, LineSplitterLogic lineSplitterLogic) throws IOException
filename
- name of the file that should be readlineSplitterLogic
- logic that is used to split lines into individual iteration stepsIOException
- If the file does not exist or could not be readCopyright © 2018 Open eHealth Foundation. All rights reserved.