if (closed) {
buffer.dispose();
return false;
}
final ReadHandler localHandler = handler;
final boolean isLast = httpContent.isLast();
// if we have a handler registered - switch the flag to true
boolean askForMoreDataInThisThread = !isLast && localHandler != null;
boolean invokeDataAvailable = false;
if (buffer.hasRemaining()) {
updateInputContentBuffer(buffer);
if (localHandler != null) {
final int available = readyData();
if (available >= requestedSize) {
invokeDataAvailable = true;
askForMoreDataInThisThread = false;
}
}
}
if (askForMoreDataInThisThread) {
// There is a ReadHandler registered, but it requested more
// data to be available before we can notify it - so wait for
// more data to come
isWaitingDataAsynchronously = true;
return true;
}
handler = null;
if (isLast) {
checkHttpTrailer(httpContent);
}
invokeHandlerOnProperThread(localHandler,
invokeDataAvailable, isLast);
} else { // broken content
final ReadHandler localHandler = handler;
handler = null;
invokeErrorHandlerOnProperThread(localHandler,
((HttpBrokenContent) httpContent).getException());
}