Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-2576 HTTP protocol implementation based on okhttp - fix: copy buffer(s) entirely to response (readFully vs. read)

Sebastian Nagel659e1c8900c6
diff --git a/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttpResponse.java b/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttpResponse.java
index 2278928b0..9571392a9 100644
--- a/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttpResponse.java
+++ b/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttpResponse.java
@@ -149,13 +149,19 @@ public class OkHttpResponse implements Response {
trimmed.setValue(true);
}
}
+ int bytesToCopy = contentBytesBuffered;
if (maxContent != -1 && contentBytesBuffered > maxContent) {
// okhttp's internal buffer is larger than maxContent
trimmed.setValue(true);
- contentBytesBuffered = maxContentBytes;
+ bytesToCopy = maxContentBytes;
+ }
+ byte[] arr = new byte[bytesToCopy];
+ source.buffer().readFully(arr);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(
+ "copied {} bytes out of {} buffered, remaining buffer contains {} bytes",
+ bytesToCopy, contentBytesBuffered, source.buffer().size());
}
- byte[] arr = new byte[contentBytesBuffered];
- source.buffer().read(arr);
return arr;
}