Class OutputStreamContentProvider
- java.lang.Object
-
- org.eclipse.jetty.client.util.OutputStreamContentProvider
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Iterable<java.nio.ByteBuffer>
,ContentProvider
,AsyncContentProvider
,Callback
,Invocable
@Deprecated(since="2021-05-27") public class OutputStreamContentProvider extends java.lang.Object implements AsyncContentProvider, Callback, java.io.Closeable
Deprecated.The Eclipse Jetty and Apache Felix Http Jetty packages are no longer supported.AContentProvider
that provides content asynchronously through anOutputStream
similar toDeferredContentProvider
.OutputStreamContentProvider
can only be used in conjunction withRequest.send(Response.CompleteListener)
(and not with its blocking counterpartRequest.send()
) because it provides content asynchronously.The deferred content is provided once by writing to the
output stream
and then fully consumed. Invocations to theiterator()
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 ofiterator()
by overridingwrite(ByteBuffer)
andclose()
, copying the bytes and making them available for subsequent invocations.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 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
Callback.Completable, Callback.Completing, 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
Invocable.InvocationType
-
-
Field Summary
-
Fields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking
-
-
Constructor Summary
Constructors Constructor Description OutputStreamContentProvider()
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
Deprecated.void
failed(java.lang.Throwable failure)
Deprecated.Callback invoked when the operation fails.Invocable.InvocationType
getInvocationType()
Deprecated.long
getLength()
Deprecated.java.io.OutputStream
getOutputStream()
Deprecated.java.util.Iterator<java.nio.ByteBuffer>
iterator()
Deprecated.void
setListener(AsyncContentProvider.Listener listener)
Deprecated.void
succeeded()
Deprecated.Callback invoked when the operation completes.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.client.api.ContentProvider
isReproducible
-
-
-
-
Method Detail
-
getInvocationType
public Invocable.InvocationType getInvocationType()
Deprecated.- Specified by:
getInvocationType
in interfaceInvocable
- Returns:
- The InvocationType of this object
-
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
public java.util.Iterator<java.nio.ByteBuffer> iterator()
Deprecated.- Specified by:
iterator
in interfacejava.lang.Iterable<java.nio.ByteBuffer>
-
setListener
public void setListener(AsyncContentProvider.Listener listener)
Deprecated.- Specified by:
setListener
in interfaceAsyncContentProvider
- Parameters:
listener
- the listener to be notified of content availability
-
getOutputStream
public java.io.OutputStream getOutputStream()
Deprecated.
-
close
public void close()
Deprecated.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
succeeded
public void succeeded()
Deprecated.Description copied from interface:Callback
Callback invoked when the operation completes.
- Specified by:
succeeded
in interfaceCallback
- See Also:
Callback.failed(Throwable)
-
-