- All Superinterfaces:
- AutoCloseable, Closeable, Iterator<T>
- All Known Subinterfaces:
- CloseableTribbleIterator<T>, SAMRecordIterator
- All Known Implementing Classes:
- CRAMFileReader.IntervalIterator, CRAMIterator, DelegatingIterator, DownsamplingIterator, DuplicateSetIterator, FilteringIterator, FilteringIterator, MergingIterator, MergingSamRecordIterator, PeekableIterator, SamLocusIterator, SamPairUtil.SetMateInfoIterator, SamReader.AssertingIterator, SRAIterator
public interface CloseableIterator<T>
extends Iterator<T>, Closeable
This interface is used by iterators that use releasable resources during iteration.
The consumer of a CloseableIterator should ensure that the close() method is always called,
for example by putting such a call in a finally block. Two conventions should be followed
by all implementors of CloseableIterator:
1) The close() method should be idempotent: calling close() twice should have no effect.
2) When hasNext() returns false, the iterator implementation should automatically close itself.
The latter makes it somewhat safer for consumers to use the for loop syntax for iteration:
for (Type obj : getCloseableIterator()) { ... }
We do not inherit from java.io.Closeable because IOExceptions are a pain to deal with.