私のAndroidアプリケーションでは、Amazonバケットからビデオをダウンロードする必要があります。Amazonバケットからビデオをダウンロードしようとすると、しばらくすると次のようなエラーが発生します
06-16 12:01:55.792: I/System.out(577): ERROR in Thread : java.io.IOException: null SSL pointer
ここにAmazons3バケットからビデオをダウンロードするためのコード
public class AmazonS3Helper
{
GeneralHelper objHelper;
Context myContext;
String bucketName;
String accessKey;
String secretKey;
ProgressBar myProgressBar;
AWSCredentials credential;
int len;
int total = 0;
public AmazonS3Helper(Context context,List list)
{
try
{
myContext = context;
objHelper = new GeneralHelper(myContext);
bucketName = "mybucketName";
accessKey = "myaccesskey";
secretKey = "mysecretkey";
credential = new BasicAWSCredentials(accessKey, secretKey);
getFileFromAmazonS3(list);
}
catch (Exception ex)
{
System.out.println("ERROR : "+ex.toString());
}
}
public AmazonS3Helper(Context context,String amazonObjectName,ProgressBar progress)
{
try
{
myContext = context;
objHelper = new GeneralHelper(myContext);
//progressBar = progress;
bucketName = "mybucketname";
accessKey = "key";
secretKey = "key";
credential = new BasicAWSCredentials(accessKey, secretKey);
getFileFromAmazonS3(amazonObjectName,progress);
}
catch (Exception ex)
{
System.out.println("ERROR : "+ex.toString());
}
}
public void getFileFromAmazonS3(List list)
{
try
{
List<DownloadItemList> downloadList = list;
List<S3Object> s3ObjectList = new ArrayList<S3Object>();
for(int i=0;i<downloadList.size();i++)
{
DownloadItemList downloadItem = downloadList.get(i);
String objectImageKey = downloadItem.getEncryptName()+".app/"+downloadItem.getImageName();
String objectAudioKey = downloadItem.getEncryptName()+".app/"+downloadItem.getAudioName();
GetObjectRequest objRequest = new GetObjectRequest(bucketName,objectImageKey);
AmazonS3Client myS3Client = new AmazonS3Client(credential);
S3Object s3Object = myS3Client.getObject(objRequest);
s3ObjectList.add(s3Object);
objRequest = new GetObjectRequest(bucketName,objectImageKey);
myS3Client = new AmazonS3Client(credential);
s3Object = myS3Client.getObject(objRequest);
s3ObjectList.add(s3Object);
}
}
catch (Exception ex)
{
System.out.println("ERROR : "+ex.toString());
}
}
// For Video
public void getFileFromAmazonS3(String strObjectName,ProgressBar progress)
{
try
{
String md5Name = objHelper.getMD5HasCode(strObjectName);
String strObjectKey = "video path";
GetObjectRequest objRequest = new GetObjectRequest(bucketName,strObjectKey);
AmazonS3Client myS3Client = new AmazonS3Client(credential);
S3Object s3Object = myS3Client.getObject(objRequest);
String filePath = strObjectName+"_video.mp4";
System.out.println("OK - 8");
downloadObject(s3Object,filePath,progress);
}
catch (Exception ex)
{
System.out.println("ERROR : "+ex.toString());
}
}
private void downloadObject(S3Object s3Object,String path,ProgressBar progress)
{
try
{
myProgressBar = progress;
System.out.println("OK - 8");
String filePath = objHelper.getFullFilePath(path); // + "noha_video1.mp4";
System.out.println("FilePath : "+filePath);
final long fileSize = s3Object.getObjectMetadata().getContentLength();
final InputStream input = s3Object.getObjectContent();
final FileOutputStream fos = new FileOutputStream(filePath);
myProgressBar.setMax((int) fileSize);
System.out.println("Input Stream Length : " + fileSize);
final byte[] buf = new byte[1024];
Thread thread = new Thread()
{
public void run()
{
try
{
total = 0;
while((len = input.read(buf)) > 0)
{
fos.write(buf,0,len);
total = total + len;
Message msg = handler.obtainMessage();
Bundle b = new Bundle();
b.putInt("total", total);
msg.setData(b);
handler.sendMessage(msg);
}
if(len == -1 && total==Integer.parseInt(String.valueOf(fileSize)))
{
Thread.currentThread().interrupt();
input.close();
fos.close();
objHelper.startTargetActivity(myContext, VideoActivity.class);
}
}
catch (Exception ex)
{
System.out.println("ERROR in Thread : "+ex.toString());
}
}
};
thread.start();
}
catch (Exception ex)
{
System.out.println("ERROR in Run Thread : "+ex.toString());
}
}
Handler handler=new Handler()
{
@Override
public void handleMessage(Message msg)
{
myProgressBar.setProgress(msg.getData().getInt("total"));
}
};
}