* @param response
* the Response to get the entity from
* @return The response entity if available.
*/
public Representation getResponseEntity(Response response) {
Representation result = null;
// boolean available = false;
long size = Representation.UNKNOWN_SIZE;
// Compute the content length
Series<Parameter> responseHeaders = getResponseHeaders();
String transferEncoding = responseHeaders.getFirstValue(
HeaderConstants.HEADER_TRANSFER_ENCODING, true);
if ((transferEncoding != null)
&& !"identity".equalsIgnoreCase(transferEncoding)) {
size = Representation.UNKNOWN_SIZE;
} else {
size = getContentLength();
}
if (!getMethod().equals(Method.HEAD.getName())
&& !response.getStatus().isInformational()
&& !response.getStatus()
.equals(Status.REDIRECTION_NOT_MODIFIED)
&& !response.getStatus().equals(Status.SUCCESS_NO_CONTENT)
&& !response.getStatus().equals(Status.SUCCESS_RESET_CONTENT)) {
// Make sure that an InputRepresentation will not be instantiated
// while the stream is closed.
InputStream stream = getUnClosedResponseEntityStream(getResponseEntityStream(size));
java.nio.channels.ReadableByteChannel channel = getResponseEntityChannel(size);
if (stream != null) {
result = getRepresentation(stream);
} else if (channel != null) {
result = getRepresentation(channel);
}
}
if (result != null) {
result.setSize(size);
// Informs that the size has not been specified in the header.
if (size == Representation.UNKNOWN_SIZE) {
getLogger()
.fine("The length of the message body is unknown. The entity must be handled carefully and consumed entirely in order to surely release the connection.");