BufferedInputStream的问题得到java.net.SocketTimeoutException:读取超时

时间:2013-07-18 14:58:15

标签: java android

下面是堆栈跟踪。

07-18 18:57:24.687: W/System.err(7031): java.net.SocketTimeoutException: Read timed out 
07-18 18:57:24.773: W/System.err(7031): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_read(Native Method) 
07-18 18:57:24.773: W/System.err(7031): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:675) 
07-18 18:57:24.773: W/System.err(7031): at libcore.io.Streams.readSingleByte(Streams.java:41) 
07-18 18:57:24.773: W/System.err(7031): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:659) 
07-18 18:57:24.773: W/System.err(7031): at libcore.io.Streams.readAsciiLine(Streams.java:201) 
07-18 18:57:24.773: W/System.err(7031): at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:560) 
07-18 18:57:24.773: W/System.err(7031): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:813) 
07-18 18:57:24.773: W/System.err(7031): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274) 
07-18 18:57:24.773: W/System.err(7031): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168) 
07-18 18:57:24.773: W/System.err(7031): at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271) 
07-18 18:57:24.773: W/System.err(7031): at com.Webservice.downloadFileAddPassword(Webservice.java:192) 
07-18 18:57:24.777: W/System.err(7031): at com.patientcontext.DocumentViewerActivity2$DocumentsShowAsyncTask.doInBackground(DocumentViewerActivity2.java:219) 
07-18 18:57:24.777: W/System.err(7031): at com.patientcontext.DocumentViewerActivity2$DocumentsShowAsyncTask.doInBackground(DocumentViewerActivity2.java:1) 
07-18 18:57:24.777: W/System.err(7031): at android.os.AsyncTask$2.call(AsyncTask.java:287) 
07-18 18:57:24.777: W/System.err(7031): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
07-18 18:57:24.777: W/System.err(7031): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
07-18 18:57:24.777: W/System.err(7031): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
07-18 18:57:24.781: W/System.err(7031): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 
07-18 18:57:24.785: W/System.err(7031): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 
07-18 18:57:24.785: W/System.err(7031): at java.lang.Thread.run(Thread.java:856)

我在这些行的第192行收到错误。

BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileData));
BufferedInputStream in = new BufferedInputStream(urlConn.getInputStream(), 8192);

如何解决问题。

1 个答案:

答案 0 :(得分:0)

  

urlConn.setReadTimeout(10000);

您将读取超时设置为10秒。

  

java.net.SocketTimeoutException:读取超时

读取超时。

您的超时时间太短,或者时间不够短,并且您在设置超时时检测到了您尝试检测的情况。