com.healthmarketscience.rmiio
Class LineIterator

java.lang.Object
  extended by com.healthmarketscience.rmiio.AbstractCloseableIOIterator<String>
      extended by com.healthmarketscience.rmiio.LineIterator
All Implemented Interfaces:
CloseableIOIterator<String>, IOIterator<String>, Closeable

public class LineIterator
extends AbstractCloseableIOIterator<String>

CloseableIOIterator that reads lines from a BufferedReader, optionally trimming whitespace and/or skipping blank lines.

Author:
James Ahlborn

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.healthmarketscience.rmiio.CloseableIOIterator
CloseableIOIterator.Adapter<DataType>
 
Constructor Summary
LineIterator(BufferedReader reader, boolean trimWhitespace, boolean skipBlankLines)
          Creates a new LineIterator instance that will read lines from the given BufferedReader and return them from calls to next().
 
Method Summary
protected  void closeImpl()
          Does the actual closing of the local resources.
 boolean hasNext()
          Returns true iff the iteration has more elements.
protected  String nextImpl()
          Does the actual work of the AbstractCloseableIOIterator.next() method.
 
Methods inherited from class com.healthmarketscience.rmiio.AbstractCloseableIOIterator
close, next
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineIterator

public LineIterator(BufferedReader reader,
                    boolean trimWhitespace,
                    boolean skipBlankLines)
             throws IOException
Creates a new LineIterator instance that will read lines from the given BufferedReader and return them from calls to next().

Parameters:
reader - the source of lines for this iterator
trimWhitespace - if true, leading and trailing whitespace will be trimmed from each line
skipBlankLines - if true, empty lines will be skipped
Throws:
IOException
Method Detail

hasNext

public boolean hasNext()
                throws IOException
Description copied from interface: IOIterator
Returns true iff the iteration has more elements.

Throws:
IOException

nextImpl

protected String nextImpl()
                   throws IOException
Description copied from class: AbstractCloseableIOIterator
Does the actual work of the AbstractCloseableIOIterator.next() method. Will only be called if IOIterator.hasNext() is currently returning true.

Specified by:
nextImpl in class AbstractCloseableIOIterator<String>
Throws:
IOException

closeImpl

protected void closeImpl()
Description copied from class: AbstractCloseableIOIterator
Does the actual closing of the local resources. Will be called at most once by the AbstractCloseableIOIterator.close() method regardless of how many times that method is invoked.

Note, this method does not throw IOException because it can be called in a variety of different scenarios and throwing an IOException would be useless in many of them (and often, failure to close is merely a nuisance, not a cause for failure).

Specified by:
closeImpl in class AbstractCloseableIOIterator<String>


Copyright © 2006–2016 Health Market Science. All rights reserved.