Class TextFileIterator

  • All Implemented Interfaces:
    Iterator<String>

    public class TextFileIterator
    extends Object
    implements Iterator<String>
    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 Detail

      • TextFileIterator

        public TextFileIterator​(String filename)
                         throws IOException
        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

        public TextFileIterator​(String filename,
                                LineSplitterLogic lineSplitterLogic)
                         throws IOException
        Creates an iterator for a given file name
        Parameters:
        filename - name of the file that should be read
        lineSplitterLogic - 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 Detail

      • 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