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 TypeMethodDescriptionvoid
close()
static <E> CloseableIterator<E>
Return an emptyCloseableIterator
.toStream()
Create aStream
from this iterator, and arrange for this iterator to be closed when the stream is closed.static <E> CloseableIterator<E>
Wrap the given plainIterator
as necessary to make it aCloseableIterator
.static <E> CloseableIterator<E>
wrap
(Iterator<E> iterator, AutoCloseable resource) Wrap the given plainIterator
to make it aCloseableIterator
, such that whenclose()
is invoked, the associatedresource
is closed.Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
Method Details
-
close
void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
wrap
Wrap the given plainIterator
as necessary to make it aCloseableIterator
.If
iterator
already implementsCloseableIterator
, theniterator
is returned.If
iterator
does not implementCloseableIterator
but 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:
CloseableIterator
wrappingiterator
, or null ifiterator
is null
-
wrap
Wrap the given plainIterator
to make it aCloseableIterator
, such that whenclose()
is invoked, the associatedresource
is 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:
CloseableIterator
wrappingiterator
, or null ifiterator
is null
-
emptyIterator
Return an emptyCloseableIterator
.- Returns:
- empty
CloseableIterator
-
toStream
Create aStream
from this iterator, and arrange for this iterator to be closed when the stream is closed.- Returns:
- this instance wrapped as a
Stream
-