Class ReaderLineIterable

java.lang.Object
uk.ac.manchester.spinnaker.utils.ReaderLineIterable
All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<String>, MappableIterable<String>

public class ReaderLineIterable
extends Object
implements MappableIterable<String>, Closeable
A simple one-shot iterable wrapper for a reader.

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