[英]java.net.SocketTimeoutException: Read timed out
我連接到 AWS(Amazon WebService) 並從特定表和數據中讀取數據 S3Link 對象使用此對象為每個項目返回圖像,因為 SocketTimeoutException 某些圖像未返回
@Override
protected List<Item> doInBackground(Void... params) {
itemList= ItemOperation.getItemList(); // get data from Amazon
Log.e(TAG,itemList.size()+"");
return itemList;
}
@Override
protected void onPostExecute(List<Item> items) {
new DownloadImage().execute(items);
}
}
public class DownloadImage extends AsyncTask<List<Item>,Void,Void>{
@Override
protected Void doInBackground(List<Item>... params) {
AmazonS3Client s3Client=new AmazonS3Client(Constants.MANAGER.getCredentials());
InputStream myObjectBytes=null;
S3Object getResponse=null;
GetObjectRequest getRequest;
for (int i=0;i<params[0].size();i++) {
String bucketName= params[0].get(i).getItemPhoto1().getBucketName();
String pictureId= params[0].get(i).getItemPhoto1().getKey();
getRequest = new GetObjectRequest(bucketName,pictureId);
getResponse = s3Client.getObject(getRequest);
myObjectBytes = getResponse.getObjectContent();
itemList.get(i).setBitmap(BitmapFactory.decodeStream(myObjectBytes));
}
try {
myObjectBytes.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
由於java.net.SocketTimeoutException
不下載異常和圖像:
08-28 21:06:20.576 709-755/com.sprintone I/art? Background sticky concurrent mark sweep GC freed 48266(2MB) AllocSpace objects, 16(444KB) LOS objects, 0% free, 21MB/21MB, paused 1.345ms total 103.715ms
08-28 21:07:04.413 709-1541/com.sprintone W/System.err? java.net.SocketTimeoutException: Read timed out
08-28 21:07:04.414 709-1541/com.sprintone W/System.err? at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
08-28 21:07:04.414 709-1541/com.sprintone W/System.err? at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:699)
08-28 21:07:04.414 709-1541/com.sprintone W/System.err? at com.android.okio.Okio$2.read(Okio.java:113)
08-28 21:07:04.414 709-1541/com.sprintone W/System.err? at com.android.okio.RealBufferedSource.read(RealBufferedSource.java:48)
08-28 21:07:04.415 709-1541/com.sprintone W/System.err? at com.android.okhttp.internal.http.HttpConnection$FixedLengthSource.read(HttpConnection.java:446)
08-28 21:07:04.415 709-1541/com.sprintone W/System.err? at com.android.okio.RealBufferedSource$1.read(RealBufferedSource.java:168)
08-28 21:07:04.415 709-1541/com.sprintone W/System.err? at com.amazonaws.internal.SdkFilterInputStream.read(SdkFilterInputStream.java:73)
08-28 21:07:04.415 709-1541/com.sprintone W/System.err? at com.amazonaws.internal.SdkFilterInputStream.read(SdkFilterInputStream.java:73)
08-28 21:07:04.415 709-1541/com.sprintone W/System.err? at java.security.DigestInputStream.read(DigestInputStream.java:113)
08-28 21:07:04.416 709-1541/com.sprintone W/System.err? at com.amazonaws.services.s3.internal.DigestValidationInputStream.read(DigestValidationInputStream.java:60)
08-28 21:07:04.416 709-1541/com.sprintone W/System.err? at com.amazonaws.internal.SdkFilterInputStream.read(SdkFilterInputStream.java:73)
08-28 21:07:04.416 709-1541/com.sprintone W/System.err? at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
08-28 21:07:04.416 709-1541/com.sprintone W/System.err? at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:635)
08-28 21:07:04.416 709-1541/com.sprintone W/System.err? at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:611)
08-28 21:07:04.425 709-1541/com.sprintone W/System.err? at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:649)
08-28 21:07:04.431 709-1541/com.sprintone W/System.err? at com.sprintone.userInterface.Fragment.FirstTabFragment$DownloadImage.doInBackground(FirstTabFragment.java:121)
08-28 21:07:04.432 709-1541/com.sprintone W/System.err? at com.sprintone.userInterface.Fragment.FirstTabFragment$DownloadImage.doInBackground(FirstTabFragment.java:107)
08-28 21:07:04.432 709-1541/com.sprintone W/System.err? at android.os.AsyncTask$2.call(AsyncTask.java:292)
08-28 21:07:04.432 709-1541/com.sprintone W/System.err? at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-28 21:07:04.434 709-1541/com.sprintone W/System.err? at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
08-28 21:07:04.435 709-1541/com.sprintone W/System.err? at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
08-28 21:07:04.436 709-1541/com.sprintone W/System.err? at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
08-28 21:07:04.437 709-1541/com.sprintone W/System.err? at java.lang.Thread.run(Thread.java:818)
08-28 21:07:04.437 709-1541/com.sprintone D/skia? ---- read threw an exception
08-28 21:07:04.437 709-1541/com.sprintone D/skia? --- decoder->decode returned false
默認連接超時和套接字超時都是 15 秒。 請參閱Github 上的源代碼。 如果您的網絡連接相對較差,請考慮通過ClientConfiguration增加超時。
ClientConfiguration config = new ClientConfiguration();
config.setConnectionTimeout(60 * 1000); // 60 sec
config.setSocketTimeout(60 * 1000); // 60 sec
AmazonS3Client s3Client = new AmazonS3Client(Constants.MANAGER.getCredentials(), config);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.