Class OutputStreamRequestContent

java.lang.Object
org.eclipse.jetty.io.content.OutputStreamContentSource
org.eclipse.jetty.client.OutputStreamRequestContent
All Implemented Interfaces:
Closeable, AutoCloseable, Request.Content, org.eclipse.jetty.io.Content.Source

public class OutputStreamRequestContent extends org.eclipse.jetty.io.content.OutputStreamContentSource implements Request.Content

A Request.Content that provides content asynchronously through an OutputStream similar to AsyncRequestContent.

OutputStreamRequestContent can only be used in conjunction with Request.send(Response.CompleteListener) (and not with its blocking counterpart Request.send()) because it provides content asynchronously.

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.
 OutputStreamRequestContent content = new OutputStreamRequestContent();
 try (OutputStream output = content.getOutputStream())
 {
     httpClient.newRequest("localhost", 8080)
             .body(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.io.Content.Source

    org.eclipse.jetty.io.Content.Source.Factory
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
     

    Methods inherited from class org.eclipse.jetty.io.content.OutputStreamContentSource

    close, demand, fail, getLength, getOutputStream, read

    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.io.Content.Source

    demand, fail, fail, getLength, read, rewind
  • Constructor Details

    • OutputStreamRequestContent

      public OutputStreamRequestContent()
    • OutputStreamRequestContent

      public OutputStreamRequestContent(String contentType)
  • Method Details