gpt4 book ai didi

javafx - JSoup 随机抛出 java.io.IOException : stream is closed when running from browser

转载 作者:行者123 更新时间:2023-12-04 21:18:49 25 4
gpt4 key购买 nike

从浏览器(或作为网络启动)运行我的 JavaFX 应用程序时,我遇到了一些奇怪的 JSoup 问题。

当我从 IDE(Eclipse 或 Netbeans)内部运行或作为独立应用程序运行时,它运行正常。当我尝试作为网络启动或从浏览器 (Chrome) 运行时,JSoup 随机抛出“java.io.IOException:流已关闭”。

我试图解析的网站是 thepiratebay.sx。当我第一次运行应用程序(从浏览器)时,我收到这个错误。随着应用程序的运行,如果我再次尝试解析,它会起作用……有时。

JSoup 代码:

try {
//TODO: Change to HttpFetcher. This method is reporting "stream is closed" when running on browser
Connection con = Jsoup.connect(url)
.timeout(HTTP_TIMEOUT)
.userAgent(UserAgentGenerator.getUserAgent())
.followRedirects(false);
doc = con.get();
System.out.println("Fetching... " + url);
} catch (IOException e) {
e.printStackTrace();
System.out.println("Parser connect must have timed out, no results. " + url);
fetchFailed[i] = true;
continue;
}
finally {
i++;
if (CommonTFUtils.isAllTrue(fetchFailed)) {
throw new HttpException("Fetcher failed on every URL of " + response.getSite_name());
}
}

并抛出异常:
CacheEntry[http://thepiratebay.sx/browse/207/0/7]: updateAvailable=true,lastModified=Tue May 14 14:28:16 BRT 2013,length=-1
java.io.IOException: stream is closed
at sun.net.www.http.ChunkedInputStream.ensureOpen(Unknown Source)
at sun.net.www.http.ChunkedInputStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.close(Unknown Source)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:468)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153)
at com.package.torrent.parser.GenericParser.search(GenericParser.java:147)
at com.package.torrent.parser.GenericParser.browse(GenericParser.java:82)
at com.package.search.TrackerSearch.searchTracker(TrackerSearch.java:69)
at com.package.search.TrackerSearch.searchAllTrackers(TrackerSearch.java:40)
at com.package.search.TrackerSearch.searchAllTrackers(TrackerSearch.java:23)
at com.package.search.MovieBrowser.browseTrackers(MovieBrowser.java:49)
at com.package.ui.browse.BrowseController$MovieBrowserTask.call(BrowseController.java:237)
at com.package.ui.browse.BrowseController$MovieBrowserTask.call(BrowseController.java:213)
at javafx.concurrent.Task$TaskCallable.call(Task.java:1259)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

有没有人知道可能导致这种情况的原因?

提前致谢。

最佳答案

我想我找到了解决方案。在调用 JSoup 之前放置此代码。显然,applet 和 web start 将此值设置为 true。现在,我想知道为什么 Sun 会强制您非静态地访问静态变量。

new URL("jar:file://dummy.jar!/").openConnection().setDefaultUseCaches(false);

当 URL 被缓存并将其视为异常时,JSoup 不能很好地处理。

关于javafx - JSoup 随机抛出 java.io.IOException : stream is closed when running from browser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16550571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com