Package io.permazen.util
Interface CloseableIterator<E>
- Type Parameters:
E- iteration element type
- All Superinterfaces:
AutoCloseable,Closeable,Iterator<E>
- All Known Implementing Classes:
AbstractKVIterator,BerkeleyKVTransaction.CursorIterator,CursorIterator,KVPairIterator,UniqueIterator
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static <E> CloseableIterator<E>Return an emptyCloseableIterator.toStream()Create aStreamfrom this iterator, and arrange for this iterator to be closed when the stream is closed.static <E> CloseableIterator<E>Wrap the given plainIteratoras necessary to make it aCloseableIterator.static <E> CloseableIterator<E>wrap(Iterator<E> iterator, AutoCloseable resource) Wrap the given plainIteratorto make it aCloseableIterator, such that whenclose()is invoked, the associatedresourceis closed.Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
Method Details
-
close
void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
wrap
Wrap the given plainIteratoras necessary to make it aCloseableIterator.If
iteratoralready implementsCloseableIterator, theniteratoris returned.If
iteratordoes not implementCloseableIteratorbut does implementCloseable(orAutoCloseable), then the returned instance will delegate toiterator.close()whenclose()is invoked, and any exception thrown will be discarded.Otherwise, invoking
close()on the returned instance does nothing.- Type Parameters:
E- iteration element type- Parameters:
iterator- nested iterator- Returns:
CloseableIteratorwrappingiterator, or null ifiteratoris null
-
wrap
Wrap the given plainIteratorto make it aCloseableIterator, such that whenclose()is invoked, the associatedresourceis closed.- Type Parameters:
E- iteration element type- Parameters:
iterator- nested iteratorresource- resource to close when the returned instance isclose()'d, or null to do nothing onclose()- Returns:
CloseableIteratorwrappingiterator, or null ifiteratoris null
-
emptyIterator
Return an emptyCloseableIterator.- Returns:
- empty
CloseableIterator
-
toStream
Create aStreamfrom this iterator, and arrange for this iterator to be closed when the stream is closed.- Returns:
- this instance wrapped as a
Stream
-