protected final void onContentReceived(
final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
Asserts.notNull(this.bbuf, "Byte buffer");
//FIXME: IOControl needs to expose event mask in order to avoid this extreme ugliness
final IOSession iosession;
if (ioctrl instanceof ManagedNHttpClientConnection) {
final ManagedNHttpClientConnection conn = (ManagedNHttpClientConnection) ioctrl;
iosession = conn != null ? conn.getIOSession() : null;
} else {
iosession = null;
}
while (!this.isDone()) {
final int bytesRead = decoder.read(this.bbuf);
if (bytesRead <= 0) {
break;
}
this.bbuf.flip();
final boolean completed = decoder.isCompleted();
CoderResult result = this.chardecoder.decode(this.bbuf, this.cbuf, completed);
handleDecodingResult(result, ioctrl);
this.bbuf.compact();
if (completed) {
result = this.chardecoder.flush(this.cbuf);
handleDecodingResult(result, ioctrl);
break;
} else {
if (iosession != null && (iosession.isClosed() ||
(iosession.getEventMask() & SelectionKey.OP_READ) == 0)) {
break;
}
}
}
}