apidocs / com.srv4pos.commons.io / LineIterator

LineIterator

open class LineIterator : MutableIterator<Any?>

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);
  }
  

Author
Niall Pemberton

Author
Stephen Colebourne

Author
Sandy McArthur

Version
$Id: LineIterator.java 437567 2006-08-28 06:39:07Z bayard $

Since
Commons IO 1.2

Constructors

<init>

LineIterator(reader: Reader!)

Constructs an iterator of the lines for a Reader.

Functions

close

open fun close(): Unit

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.

closeQuietly

open static fun closeQuietly(iterator: LineIterator!): Unit

Closes the iterator, handling null and ignoring exceptions.

hasNext

open fun hasNext(): Boolean

Indicates whether the Reader has more lines. If there is an IOException then #close() will be called on this instance.

isValidLine

open fun isValidLine(line: String!): Boolean

Overridable method to validate each line that is returned.

next

open fun next(): Any?

Returns the next line in the wrapped Reader.

nextLine

open fun nextLine(): String!

Returns the next line in the wrapped Reader.

remove

open fun remove(): Unit

Unsupported.