Package org.eclipse.jetty.client.util
Class InputStreamContentProvider.InputStreamContentProviderIterator
- java.lang.Object
-
- org.eclipse.jetty.client.util.InputStreamContentProvider.InputStreamContentProviderIterator
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.util.Iterator<java.nio.ByteBuffer>
- Enclosing class:
- InputStreamContentProvider
private class InputStreamContentProvider.InputStreamContentProviderIterator extends java.lang.Object implements java.util.Iterator<java.nio.ByteBuffer>, java.io.CloseableIterating over anInputStreamis tricky, becausehasNext()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 byhasNext(), 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
truefromhasNext()even if we don't know that we will read -1, but then whennext()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) untilnext()is called.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateInputStreamContentProviderIterator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()booleanhasNext()java.nio.ByteBuffernext()voidremove()
-
-
-
Method Detail
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfacejava.util.Iterator<java.nio.ByteBuffer>
-
next
public java.nio.ByteBuffer next()
- Specified by:
nextin interfacejava.util.Iterator<java.nio.ByteBuffer>
-
remove
public void remove()
- Specified by:
removein interfacejava.util.Iterator<java.nio.ByteBuffer>
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-