Class InputStreamContentProvider.InputStreamContentProviderIterator

java.lang.Object
org.eclipse.jetty.client.util.InputStreamContentProvider.InputStreamContentProviderIterator
All Implemented Interfaces:
Closeable, AutoCloseable, Iterator<ByteBuffer>
Enclosing class:
InputStreamContentProvider

private class InputStreamContentProvider.InputStreamContentProviderIterator extends Object implements Iterator<ByteBuffer>, Closeable
Iterating over an InputStream is tricky, because hasNext() must return false if the stream reads -1. However, we don't know what to return until we read the stream, which means that stream reading must be performed by hasNext(), which introduces a side-effect on what is supposed to be a simple query method (with respect to the Query Command Separation Principle).

Alternatively, we could return true from hasNext() even if we don't know that we will read -1, but then when next() reads -1 it must return an empty buffer. However this is problematic, since GETs with no content indication would become GET with chunked content, and not understood by servers.

Therefore we need to make sure that hasNext() does not perform any side effect (so that it can be called multiple times) until next() is called.