我的程序正在读取这个大的 gzip 文件,它运行了一个小时,所以它失败了,并显示以下堆栈跟踪:
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:884)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:102)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:166)
at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:90)
at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:212)
at org.apache.http.impl.conn.LoggingSessionInputBuffer.read(LoggingSessionInputBuffer.java:82)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:182)
at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:138)
at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:238)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:116)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:154)
at java.io.BufferedReader.readLine(BufferedReader.java:317)
at java.io.BufferedReader.readLine(BufferedReader.java:382)
at com.trainchaser.feed.connections.StaticConnect.getScheduleFile(StaticConnect.java:116)
at com.trainchaser.app.App.main(App.java:32)
其中 lineStaticConnect.getScheduleFile(StaticConnect.java:116)
是下面代码中的 while 循环。
我已经阅读过类似的帖子,并且在in
阅读完 while 循环后确实关闭了阅读器(),但它仍然给我同样的错误。所以我想也许如果我使用它会起作用的实体,就像这样:
HttpEntity entity=getResponse.getEntity();
BufferedReader in = new BufferedReader(new InputStreamReader(
new GZIPInputStream(entity.getContent())));
EntityUtils.consumeQuietly(entity);
try
{
while ((content = in.readLine()) != null)
{...
那行得通吗?我在想,如果我暂时存储 gzip 文件并且没有连续分配连接将有助于防止错误。我会自己测试它,但我目前正在测试关闭防火墙的修复,看看它是否仍然出错。
org.apache.http.HttpEntity
如果有帮助,我正在使用