int length = stream.readInt();
if (stream.available() < length) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("insufficient data. require " + length + " got " + stream.available());
}
throw new BufferUnderflowException();
} else {
// ...yes, remove mark
if (!removeLengthField) {
stream.resetToReadMark();