Class BufferingResponseListener
java.lang.Object
org.eclipse.jetty.client.BufferingResponseListener
- 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
- Direct Known Subclasses:
CompletableResponseListener, ContinueProtocolHandler.ContinueListener, FutureResponseListener
Implementation of Response.Listener that buffers the content up to a maximum length
specified to the constructors.
The content may be retrieved from Response.Listener.onSuccess(Response) or onComplete(Result)
via getContent() or getContentAsString().
Instances of this class are not reusable, so one must be allocated for each request.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an instance with a default maximum length of 2 MiB.BufferingResponseListener(int maxLength) Creates an instance with the given maximum length -
Method Summary
Modifier and TypeMethodDescriptionbyte[]getContentAsString(String encoding) getContentAsString(Charset encoding) abstract voidonComplete(Result result) Callback method invoked when the request and the response have been processed, either successfully or not.voidonContent(Response response, ByteBuffer content) Callback method invoked when the response content has been received, parsed and there is demand.voidCallback method invoked when all the response headers have been received and parsed.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Response.AsyncContentListener
onContentSourceMethods inherited from interface Response.ContentListener
onContentMethods inherited from interface Response.Listener
onBegin, onFailure, onHeader, onSuccess
-
Constructor Details
-
BufferingResponseListener
public BufferingResponseListener()Creates an instance with a default maximum length of 2 MiB. -
BufferingResponseListener
public BufferingResponseListener(int maxLength) Creates an instance with the given maximum length- Parameters:
maxLength- the maximum length of the content
-
-
Method Details
-
onHeaders
Description copied from interface:Response.HeadersListenerCallback method invoked when all the response headers have been received and parsed.- Specified by:
onHeadersin interfaceResponse.HeadersListener- Specified by:
onHeadersin interfaceResponse.Listener- Parameters:
response- the response containing the response line data and the headers
-
onContent
Description copied from interface:Response.ContentListenerCallback method invoked when the response content has been received, parsed and there is demand. This method may be invoked multiple times, and thecontentbuffer must be consumed (or copied) before returning from this method. This method is also always invoked when content arrives as demand is automatically registered on return.- Specified by:
onContentin interfaceResponse.ContentListener- Specified by:
onContentin interfaceResponse.Listener- Parameters:
response- the response containing the response line data and the headerscontent- the content bytes received
-
onComplete
Description copied from interface:Response.CompleteListenerCallback method invoked when the request and the response have been processed, either successfully or not.The
resultparameter contains the request, the response, and eventual failures.Requests may complete after response, for example in case of big uploads that are discarded or read asynchronously by the server. This method is always invoked after
Response.SuccessListener.onSuccess(Response)orResponse.FailureListener.onFailure(Response, Throwable), and only when request indicates that it is completed.- Specified by:
onCompletein interfaceResponse.CompleteListener- Specified by:
onCompletein interfaceResponse.Listener- Parameters:
result- the result of the request / response exchange
-
getMediaType
-
getEncoding
-
getContent
public byte[] getContent()- Returns:
- the content as bytes
- See Also:
-
getContentAsString
- Returns:
- the content as a string, using the "Content-Type" header to detect the encoding or defaulting to UTF-8 if the encoding could not be detected.
- See Also:
-
getContentAsString
-
getContentAsString
-
getContentAsInputStream
- Returns:
- Content as InputStream
-