Class OutputStreamContentProvider
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterable<ByteBuffer>
,ContentProvider
,AsyncContentProvider
,org.eclipse.jetty.util.Callback
,org.eclipse.jetty.util.thread.Invocable
ContentProvider
that provides content asynchronously through an OutputStream
similar to DeferredContentProvider
.
OutputStreamContentProvider
can only be used in conjunction with
Request.send(Response.CompleteListener)
(and not with its blocking counterpart Request.send()
)
because it provides content asynchronously.
The deferred content is provided once by writing to the output stream
and then fully consumed.
Invocations to the iterator()
method after the first will return an "empty" iterator
because the stream has been consumed on the first invocation.
However, it is possible for subclasses to support multiple invocations of iterator()
by overriding write(ByteBuffer)
and close()
, copying the bytes and making them
available for subsequent invocations.
Content must be provided by writing to the output stream
, that must be
closed
when all content has been provided.
Example usage:
HttpClient httpClient = ...; // Use try-with-resources to autoclose the output stream OutputStreamContentProvider content = new OutputStreamContentProvider(); try (OutputStream output = content.getOutputStream()) { httpClient.newRequest("localhost", 8080) .content(content) .send(new Response.CompleteListener() { @Override public void onComplete(Result result) { // Your logic here } }); // At a later time... output.write("some content".getBytes()); }
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.client.AsyncContentProvider
AsyncContentProvider.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.Callback
org.eclipse.jetty.util.Callback.Completable, org.eclipse.jetty.util.Callback.Completing, org.eclipse.jetty.util.Callback.Nested
Nested classes/interfaces inherited from interface org.eclipse.jetty.client.api.ContentProvider
ContentProvider.Typed
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
org.eclipse.jetty.util.thread.Invocable.InvocationType, org.eclipse.jetty.util.thread.Invocable.ReadyTask, org.eclipse.jetty.util.thread.Invocable.Task
-
Field Summary
Fields inherited from interface org.eclipse.jetty.util.Callback
NOOP
Fields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Deprecated.void
Deprecated.org.eclipse.jetty.util.thread.Invocable.InvocationType
Deprecated.long
Deprecated.Deprecated.iterator()
Deprecated.void
setListener
(AsyncContentProvider.Listener listener) Deprecated.void
Deprecated.protected void
write
(ByteBuffer buffer) Deprecated.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.Callback
completeWith
Methods inherited from interface org.eclipse.jetty.client.api.ContentProvider
isReproducible
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
OutputStreamContentProvider
public OutputStreamContentProvider()Deprecated.
-
-
Method Details
-
getInvocationType
public org.eclipse.jetty.util.thread.Invocable.InvocationType getInvocationType()Deprecated.- Specified by:
getInvocationType
in interfaceorg.eclipse.jetty.util.thread.Invocable
-
getLength
public long getLength()Deprecated.- Specified by:
getLength
in interfaceContentProvider
- Returns:
- the content length, if known, or -1 if the content length is unknown
-
iterator
Deprecated.- Specified by:
iterator
in interfaceIterable<ByteBuffer>
-
setListener
Deprecated.- Specified by:
setListener
in interfaceAsyncContentProvider
- Parameters:
listener
- the listener to be notified of content availability
-
getOutputStream
Deprecated. -
write
Deprecated. -
close
public void close()Deprecated.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
succeeded
public void succeeded()Deprecated.- Specified by:
succeeded
in interfaceorg.eclipse.jetty.util.Callback
-
failed
Deprecated.- Specified by:
failed
in interfaceorg.eclipse.jetty.util.Callback
-
OutputStreamRequestContent
instead