ConnState connState = (ConnState) context.getAttribute(
CONN_STATE);
try {
WritableByteChannel channel = connState.getInputChannel();
long transferred;
// Test if the decoder is capable of direct transfer to file
if (this.useFileChannels &&
decoder instanceof FileContentDecoder &&
channel instanceof FileChannel) {
long pos = connState.getInputCount();
transferred = ((FileContentDecoder) decoder).transfer(
(FileChannel) channel, pos, Integer.MAX_VALUE);
} else {
ByteBuffer buf = connState.getInbuf();
decoder.read(buf);
buf.flip();
transferred = channel.write(buf);
buf.compact();
}
connState.incrementInputCount(transferred);
if (decoder.isCompleted()) {
// Request entity has been fully received
channel.close();
doService(conn, connState);
}
} catch (HttpException ex) {
shutdownConnection(conn);