public final class ConsumerStreamingIterator<T> extends Object implements StreamingIterator<T>
StreamingIterator
that takes its elements from a Consumer
.
Closing this iterator will cause the underlying consumer to be closed. If for any reason the underlying consumer gets closed (either because this iterator closed it or some other reason), then this iterator will consider that it has no more items.
Constructor and Description |
---|
ConsumerStreamingIterator(Consumer<T> consumer) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the underlying consumer
|
int |
getSize()
Returns
this object's size. |
boolean |
hasNext()
Returns true as long as the underlying consumer is not fully consumed nor closed
|
T |
next()
Gets an item from the consumer and returns it
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
remove
forEachRemaining
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public boolean hasNext()
public T next()
public int getSize()
HasSize
this
object's size.
In some scenarios, it might not be possible/convenient to actually retrieve this value
or it might not be available at this point. -1
is returned in such a case.
Copyright © 2018. All rights reserved.