Class ReaderLineIterable
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterable<String>
,MappableIterable<String>
public class ReaderLineIterable extends Object implements MappableIterable<String>, Closeable
It has been designed for a single use in a for statement. A second use will of the same Object will cause an Exception.
Any Exception thrown by the Reader during iteration are intercepted and not throw.
The Iterator will automatically close the underlying reader when
Iterator.hasNext()
returns false, which includes when it leaves a for
loop. Any Exception thrown by the Reader during this close are intercepted
and not throw.
It is recommended to always specifically call the Iterable's close method
after finishing with the Iteration. It makes sure the underlying reader has
been closed. It also raises the first Exception that may have been trapped
during an early Iterator.next()
or Iterator.hasNext()
including during the reader closed done then. The recommended way to make
sure close is called is with a try
-with-resources statement.
- Author:
- Donal Fellows, Christian
-
Constructor Summary
Constructors Constructor Description ReaderLineIterable(InputStream inputStream)
Create a new one-shot iterable.ReaderLineIterable(Reader reader)
Create a new one-shot iterable. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface uk.ac.manchester.spinnaker.utils.MappableIterable
filter, first, first, map, nth, toCollectingMap, toCollectingMap, toCollectingMap, toCollectingMap, toList, toList, toMap, toMap, toSet, toSet
-
Constructor Details
-
ReaderLineIterable
Create a new one-shot iterable.- Parameters:
inputStream
- The input stream to read from, using UTF-8 as the encoding.
-
ReaderLineIterable
Create a new one-shot iterable.- Parameters:
reader
- The reader to read from.
-
-
Method Details
-
iterator
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-