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.Closeable
Iterating over anInputStream
is 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
true
fromhasNext()
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 private
InputStreamContentProviderIterator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
boolean
hasNext()
java.nio.ByteBuffer
next()
void
remove()
-
-
-
Method Detail
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfacejava.util.Iterator<java.nio.ByteBuffer>
-
next
public java.nio.ByteBuffer next()
- Specified by:
next
in interfacejava.util.Iterator<java.nio.ByteBuffer>
-
remove
public void remove()
- Specified by:
remove
in interfacejava.util.Iterator<java.nio.ByteBuffer>
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
-