Package it.unimi.dsi.io
Class LineIterator
- java.lang.Object
-
- it.unimi.dsi.io.LineIterator
-
- All Implemented Interfaces:
ObjectIterator<MutableString>,Iterator<MutableString>
public class LineIterator extends Object implements ObjectIterator<MutableString>
An adapter that exposes a fast buffered reader as an iterator over the returned lines. Since we just actually read a line to know whetherhasNext()should return true, the last line read from the underlying fast buffered reader has to be cached. Mixing calls to this adapter and to the underlying fast buffered reader will not usually give the expected results.Since this class allocates no resource, it is not
Closeableand it will not close the underlyingFastBufferedReaderunder any circumstances. If you need resource handling, tryFileLinesCollection.This class reuses the same mutable strings. As a result, the comments for
FileLinesCollectionapply here. If you want just get all the remaining lines, useallLines().
-
-
Constructor Summary
Constructors Constructor Description LineIterator(FastBufferedReader fastBufferedReader)Creates a new line iterator over a specified fast buffered reader.LineIterator(FastBufferedReader fastBufferedReader, ProgressLogger pl)Creates a new line iterator over a specified fast buffered reader.
-
Method Summary
Modifier and Type Method Description List<MutableString>allLines()Returns all lines remaining in this iterator as a list.booleanhasNext()MutableStringnext()-
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, remove
-
Methods inherited from interface it.unimi.dsi.fastutil.objects.ObjectIterator
skip
-
-
-
-
Constructor Detail
-
LineIterator
public LineIterator(FastBufferedReader fastBufferedReader, ProgressLogger pl)
Creates a new line iterator over a specified fast buffered reader.- Parameters:
fastBufferedReader- the underlying buffered reader.pl- an optional progress logger, ornull.
-
LineIterator
public LineIterator(FastBufferedReader fastBufferedReader)
Creates a new line iterator over a specified fast buffered reader.- Parameters:
fastBufferedReader- the underlying buffered reader.
-
-
Method Detail
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfaceIterator<MutableString>
-
next
public MutableString next()
- Specified by:
nextin interfaceIterator<MutableString>
-
allLines
public List<MutableString> allLines()
Returns all lines remaining in this iterator as a list.- Returns:
- all lines remaining in this iterator as a list.
-
-