Class InputStreamResponseListener

java.lang.Object
org.eclipse.jetty.client.InputStreamResponseListener
All Implemented Interfaces:
EventListener, Response.AsyncContentListener, Response.BeginListener, Response.CompleteListener, Response.ContentListener, Response.ContentSourceListener, Response.FailureListener, Response.HeaderListener, Response.HeadersListener, Response.Listener, Response.ResponseListener, Response.SuccessListener

public class InputStreamResponseListener extends Object implements Response.Listener
Implementation of Response.Listener that produces an InputStream that allows applications to read the response content.

Typical usage is:

 InputStreamResponseListener listener = new InputStreamResponseListener();
 client.newRequest(...).send(listener);

 // Wait for the response headers to arrive
 Response response = listener.get(5, TimeUnit.SECONDS);
 if (response.getStatus() == 200)
 {
     // Obtain the input stream on the response content
     try (InputStream input = listener.getInputStream())
     {
         // Read the response content
     }
 }
 

The HttpClient implementation (the producer) will feed the input stream asynchronously while the application (the consumer) is reading from it.

If the consumer is faster than the producer, then the consumer will block with the typical InputStream.read() semantic. If the consumer is slower than the producer, then the producer will block until the client consumes.