public class BufferingResponseListener extends Response.Listener.Empty
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.Empty.onSuccess(Response)
or Response.Listener.Empty.onComplete(Result)
via getContent()
or getContentAsString()
.
Response.Listener.Empty
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() |
String |
getContentAsString() |
String |
getContentAsString(String encoding) |
String |
getEncoding() |
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.
|
onBegin, onComplete, onFailure, onSuccess
public BufferingResponseListener()
public BufferingResponseListener(int maxLength)
maxLength
- the maximum length of the contentpublic void onHeaders(Response response)
Response.Listener
onHeaders
in interface Response.Listener
onHeaders
in class Response.Listener.Empty
response
- the response containing the response line data and the headerspublic void onContent(Response response, ByteBuffer content)
Response.Listener
content
buffer must be consumed
before returning from this method.onContent
in interface Response.Listener
onContent
in class Response.Listener.Empty
response
- the response containing the response line data and the headerscontent
- the content bytes receivedpublic String getEncoding()
public byte[] getContent()
getContentAsString()
public String getContentAsString()
getContentAsString(String)
public String getContentAsString(String encoding)
encoding
- the encoding of the content bytesgetContentAsString()
Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.