apidocs / com.srv4pos.commons.io / IOUtils / lineIterator

lineIterator

open static fun lineIterator(reader: Reader!): LineIterator!

Return an Iterator for the lines in a Reader.

LineIterator holds a reference to the open Reader specified here. 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 LineIterator#close() or LineIterator#closeQuietly(LineIterator).

The recommended usage pattern is:


      try {
        LineIterator it = IOUtils.lineIterator(reader);
        while (it.hasNext()) {
          String line = it.nextLine();
          /// do something with line
        }
      } finally {
        IOUtils.closeQuietly(reader);
      }
      

Parameters

reader - Reader!: the Reader to read from, not null

Exceptions

IllegalArgumentException - if the reader is null

Return
LineIterator!: an Iterator of the lines in the reader, never null

Since
Commons IO 1.2

open static fun lineIterator(input: InputStream!, encoding: String!): LineIterator!

Return an Iterator for the lines in an InputStream, using the character encoding specified (or default encoding if null).

LineIterator holds a reference to the open InputStream specified here. When you have finished with the iterator you should close the stream to free internal resources. This can be done by closing the stream directly, or by calling LineIterator#close() or LineIterator#closeQuietly(LineIterator).

The recommended usage pattern is:


      try {
        LineIterator it = IOUtils.lineIterator(stream, "UTF-8");
        while (it.hasNext()) {
          String line = it.nextLine();
          /// do something with line
        }
      } finally {
        IOUtils.closeQuietly(stream);
      }
      

Parameters

input - InputStream!: the InputStream to read from, not null

encoding - String!: the encoding to use, null means platform default

Exceptions

IllegalArgumentException - if the input is null

IOException - if an I/O error occurs, such as if the encoding is invalid

Return
LineIterator!: an Iterator of the lines in the reader, never null

Since
Commons IO 1.2