E
- The Stream
and Iterator
type.public final class StreamIterator<E>
extends java.lang.Object
implements java.util.Iterator<E>, java.lang.AutoCloseable
Stream
as a AutoCloseable
Iterator
resource that automatically closes itself when reaching the end of stream.
In order to close the stream, the call site MUST either close the stream it allocated OR call this iterator until the end.
Modifier and Type | Field and Description |
---|---|
private boolean |
closed
Whether
close() has been called. |
private java.util.Iterator<E> |
iterator
The given stream's Iterator.
|
private java.util.stream.Stream<E> |
stream
The given stream.
|
Modifier | Constructor and Description |
---|---|
private |
StreamIterator(java.util.stream.Stream<E> stream) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the underlying stream.
|
boolean |
hasNext() |
static <T> StreamIterator<T> |
iterator(java.util.stream.Stream<T> stream)
Wraps and presents a stream as a closable resource that automatically closes itself when reaching the end of stream.
|
E |
next() |
private final java.util.Iterator<E> iterator
private final java.util.stream.Stream<E> stream
private boolean closed
close()
has been called.private StreamIterator(java.util.stream.Stream<E> stream)
public static <T> StreamIterator<T> iterator(java.util.stream.Stream<T> stream)
Warning
In order to close the stream, the call site MUST either close the stream it allocated OR call this iterator until the end.
T
- The stream and iterator type.stream
- The stream iterate.public void close()
close
in interface java.lang.AutoCloseable
public boolean hasNext()
hasNext
in interface java.util.Iterator<E>