// to the out ContentHandler, if we are in the body,
// else appends the characters to the pendingBuffer
private void pushBytes() throws IOException, SAXException, TikaException {
if (pendingByteCount > 0 && (!groupState.ignore || nextMetaData != null)) {
final CharsetDecoder decoder = getDecoder();
pendingByteBuffer.limit(pendingByteCount);
assert pendingByteBuffer.position() == 0;
assert outputBuffer.position() == 0;
while (true) {
// We pass true for endOfInput because, when
// we are called, we should have seen a
// complete sequence of characters for this
// charset:
final CoderResult result = decoder.decode(pendingByteBuffer, outputBuffer, true);
final int pos = outputBuffer.position();
if (pos > 0) {
if (inHeader || fieldState == 1) {
pendingBuffer.append(outputArray, 0, pos);
} else {
lazyStartParagraph();
out.characters(outputArray, 0, pos);
}
outputBuffer.position(0);
}
if (result == CoderResult.UNDERFLOW) {
break;
}
}
while (true) {
final CoderResult result = decoder.flush(outputBuffer);
final int pos = outputBuffer.position();
if (pos > 0) {
if (inHeader || fieldState == 1) {
pendingBuffer.append(outputArray, 0, pos);
} else {
lazyStartParagraph();
out.characters(outputArray, 0, pos);
}
outputBuffer.position(0);
}
if (result == CoderResult.UNDERFLOW) {
break;
}
}
// Reset for next decode
decoder.reset();
pendingByteBuffer.position(0);
}
pendingByteCount = 0;
}