Module org.eclipse.jetty.client
Package org.eclipse.jetty.client.util
Class OutputStreamRequestContent
- java.lang.Object
-
- org.eclipse.jetty.client.util.AsyncRequestContent
-
- org.eclipse.jetty.client.util.OutputStreamRequestContent
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,Request.Content
,Request.Content.Subscription
public class OutputStreamRequestContent extends AsyncRequestContent
A
Request.Content
that provides content asynchronously through anOutputStream
similar toAsyncRequestContent
.OutputStreamRequestContent
can only be used in conjunction withRequest.send(Response.CompleteListener)
(and not with its blocking counterpartRequest.send()
) because it provides content asynchronously.Content must be provided by writing to the
output stream
that must beclosed
when all content has been provided.Example usage:
HttpClient httpClient = ...; // Use try-with-resources to autoclose the output stream. OutputStreamRequestContent content = new OutputStreamRequestContent(); 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()); // Even later... output.write("more content".getBytes()); } // Implicit call to output.close().
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.client.api.Request.Content
Request.Content.Consumer, Request.Content.Subscription
-
-
Constructor Summary
Constructors Constructor Description OutputStreamRequestContent()
OutputStreamRequestContent(java.lang.String contentType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.OutputStream
getOutputStream()
-
Methods inherited from class org.eclipse.jetty.client.util.AsyncRequestContent
close, demand, fail, flush, getContentType, getLength, isClosed, offer, offer, subscribe, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.client.api.Request.Content
isReproducible
-
-