boolean connectionClose = HeaderUtils.isConnectionClose(headers);
// Create the representation
if ((contentLength != Representation.UNKNOWN_SIZE && contentLength != 0)
|| chunkedEncoding || connectionClose) {
ReadableSelectionChannel inboundEntityChannel = null;
if (chunkedEncoding) {
// Wraps the remaining bytes into a special buffer channel
inboundEntityChannel = new ReadableChunkedChannel(this,
getBuffer(), getConnection()
.getReadableSelectionChannel());
} else {
// Wrap the buffer channel to control its announced size
inboundEntityChannel = new ReadableSizedSelectionChannel(this,
getBuffer(), getConnection()
.getReadableSelectionChannel(), contentLength);
}
setEntityRegistration(inboundEntityChannel.getRegistration());
if (inboundEntityChannel != null) {
result = new ReadableRepresentation(inboundEntityChannel, null,
contentLength);
result.setSize(contentLength);