Class TextFileIterator
java.lang.Object
org.openehealth.ipf.platform.camel.core.process.splitter.support.TextFileIterator
String-based iterator class that reads a file line by line
This class can be used within a split rule expression to extract each line
of a given file and generate a new exchange via the
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()
.- Author:
- Jens Riemschneider
-
Constructor Summary
ConstructorDescriptionTextFileIterator
(String filename) Creates an iterator for a given file nameTextFileIterator
(String filename, LineSplitterLogic lineSplitterLogic) Creates an iterator for a given file name -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
TextFileIterator
Creates an iterator for a given file name- Parameters:
filename
- name of the file that should be read- Throws:
IOException
- If the file does not exist or could not be read
-
TextFileIterator
Creates an iterator for a given file name- Parameters:
filename
- name of the file that should be readlineSplitterLogic
- logic that is used to split lines into individual iteration steps- Throws:
IOException
- If the file does not exist or could not be read
-
-
Method Details
-
hasNext
public boolean hasNext() -
next
-
remove
public void remove() -
isClosed
public boolean isClosed()- Returns:
true
if any underlying resources were closed
-
close
public void close()Closes any open resources and stops an active iteration
-