public abstract class BufferingResponseListener extends Response.Listener.Adapter
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.Adapter.onSuccess(Response)
or onComplete(Result)
via getContent()
or getContentAsString()
.
Response.Listener.Adapter
Constructor and Description |
---|
BufferingResponseListener()
Creates an instance with a default maximum length of 2 MiB.
|
BufferingResponseListener(int maxLength)
Creates an instance with the given maximum length
|
Modifier and Type | Method and Description |
---|---|
byte[] |
getContent() |
InputStream |
getContentAsInputStream() |
String |
getContentAsString() |
String |
getContentAsString(Charset encoding) |
String |
getContentAsString(String encoding) |
String |
getEncoding() |
String |
getMediaType() |
abstract void |
onComplete(Result result)
Callback method invoked when the request and the response have been processed,
either successfully or not.
|
void |
onContent(Response response,
ByteBuffer content)
Callback method invoked when the response content has been received.
|
void |
onHeaders(Response response)
Callback method invoked when the response headers have been received and parsed.
|
public BufferingResponseListener()
public BufferingResponseListener(int maxLength)
maxLength
- the maximum length of the contentpublic void onHeaders(Response response)
Response.HeadersListener
onHeaders
in interface Response.HeadersListener
onHeaders
in class Response.Listener.Adapter
response
- the response containing the response line data and the headerspublic void onContent(Response response, ByteBuffer content)
Response.ContentListener
content
buffer must be consumed
before returning from this method.onContent
in interface Response.ContentListener
onContent
in class Response.Listener.Adapter
response
- the response containing the response line data and the headerscontent
- the content bytes receivedpublic abstract void onComplete(Result result)
Response.CompleteListener
result
parameter 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)
or
Response.FailureListener.onFailure(Response, Throwable)
, and only when request indicates that
it is completed.onComplete
in interface Response.CompleteListener
onComplete
in class Response.Listener.Adapter
result
- the result of the request / response exchangepublic String getMediaType()
public String getEncoding()
public byte[] getContent()
getContentAsString()
public String getContentAsString()
getContentAsString(String)
public String getContentAsString(String encoding)
encoding
- the encoding of the content bytesgetContentAsString()
public String getContentAsString(Charset encoding)
encoding
- the encoding of the content bytesgetContentAsString()
public InputStream getContentAsInputStream()
Copyright © 1995-2015 Webtide. All Rights Reserved.