diff --git a/src/main/java/org/htmlunit/cyberneko/HTMLScanner.java b/src/main/java/org/htmlunit/cyberneko/HTMLScanner.java index d35306d8..3a7f428a 100644 --- a/src/main/java/org/htmlunit/cyberneko/HTMLScanner.java +++ b/src/main/java/org/htmlunit/cyberneko/HTMLScanner.java @@ -2341,10 +2341,8 @@ protected String nextContent(final int len) throws IOException { for (nbRead = 0; nbRead < len; ++nbRead) { // read() should not clear the buffer if (fCurrentEntity.offset_ == fCurrentEntity.length_) { - if (fCurrentEntity.length_ == fCurrentEntity.buffer_.length) { - fCurrentEntity.load(fCurrentEntity.buffer_.length); - } - else { // everything was already loaded + final int count = fCurrentEntity.load(fCurrentEntity.offset_); + if (count == -1) { break; } }