共計 2891 個字符,預計需要花費 8 分鐘才能閱讀完成。
丸趣 TV 小編今天帶大家了解運行 nutch 報錯 unzipBestEffort returned null 怎么辦,文中知識點介紹的非常詳細。覺得有幫助的朋友可以跟著丸趣 TV 小編一起瀏覽文章的內容,希望能夠幫助更多想解決這個問題的朋友找到問題的答案,下面跟著丸趣 TV 小編一起深入學習“運行 nutch 報錯 unzipBestEffort returned null 怎么辦”的知識吧。
報錯信息:fetch of http://szs.mof.gov.cn/zhengwuxinxi/zhengcefabu/201402/t20140224_1046354.html failed with: java.io.IOException: unzipBestEffort returned null
完整的報錯信息為:
2014-03-12 16:48:38,031 ERROR http.Http - Failed to get protocol output
java.io.IOException: unzipBestEffort returned null
at org.apache.nutch.protocol.http.api.HttpBase.processGzipEncoded(HttpBase.java:317)
at org.apache.nutch.protocol.http.HttpResponse. init (HttpResponse.java:164)
at org.apache.nutch.protocol.http.Http.getResponse(Http.java:64)
at org.apache.nutch.protocol.http.api.HttpBase.getProtocolOutput(HttpBase.java:140)
at org.apache.nutch.fetcher.Fetcher$FetcherThread.run(Fetcher.java:703)
2014-03-12 16:48:38,031 INFO fetcher.Fetcher - fetch of http://szs.mof.gov.cn/zhengwuxinxi/zhengcefabu/201402/t20140224_1046354.html failed with: java.io.IOException: unzipBestEffort returned null
2014-03-12 16:48:38,031 INFO fetcher.Fetcher - -finishing thread FetcherThread, activeThreads=0
由此可知拋出異常的代碼位于 src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java(lib-http 插件)類的 processGzipEncoded 方法的 317 行:
byte[] content;
if (getMaxContent() = 0) { content = GZIPUtils.unzipBestEffort(compressed, getMaxContent());
} else { content = GZIPUtils.unzipBestEffort(compressed);
if (content == null)
throw new IOException(unzipBestEffort returned null
nutch2.7\src\plugin\protocol-http\src\java\org\apache\nutch\protocol\http\HttpResponse.java(protocol-http 插件)的 164 行調用了 processGzipEncoded 方法:
readPlainContent(in);
String contentEncoding = getHeader(Response.CONTENT_ENCODING);
if (gzip .equals(contentEncoding) || x-gzip .equals(contentEncoding)) {content = http.processGzipEncoded(content, url);
} else if (deflate .equals(contentEncoding)) {content = http.processDeflateEncoded(content, url);
} else {if (Http.LOG.isTraceEnabled()) {Http.LOG.trace( fetched + content.length + bytes from + url);
}
通過 Firefox 的 Firebug 工具可查看該 URL 的響應頭為 Content-Encoding:gzip,Transfer-Encoding:chunked。
解決方法如下:
1、修改文件 nutch2.7\src\java\org\apache\nutch\metadata\HttpHeaders.java,增加一個 field:
public final static String TRANSFER_ENCODING = Transfer-Encoding
2、修改文件 nutch2.7\src\plugin\protocol-http\src\java\org\apache\nutch\protocol\http\HttpResponse.java,替換第 160 行代碼 readPlainContent(in); 為如下代碼
String transferEncoding = getHeader(Response.TRANSFER_ENCODING);
if(transferEncoding != null chunked .equalsIgnoreCase(transferEncoding.trim())){
readChunkedContent(in, line);
}else{ readPlainContent(in);
}
3、http 內容長度限制不能使用負值,只能使用一個大整數:
property
name http.content.limit /name
value 655360000 /value
/property
4、因為修改了核心代碼和插件代碼,所以需要重新編譯打包發布,執行 nutch2.7\build.xml 的默認 target:runtime
cd nutch2.7
ant
感謝大家的閱讀,以上就是“運行 nutch 報錯 unzipBestEffort returned null 怎么辦”的全部內容了,學會的朋友趕緊操作起來吧。相信丸趣 TV 丸趣 TV 小編一定會給大家帶來更優質的文章。謝謝大家對丸趣 TV 網站的支持!