【发布时间】:2016-03-31 10:11:08
【问题描述】:
我在 S3 的存储桶中有一些 .zip 文件。我需要解压缩并需要将其保存回没有本地文件系统的存储桶中。
我知道 S3 是静态存储,但我可以通过提供 s3 存储桶路径在 s3 本身上解压缩文件。
我有以下问题。
-
我可以将存储桶/文件夹的路径传递给
FileOutputStream(bucketPath),以便它直接在那里解压缩文件。BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
S3Object.putObject()也接受 inputstream 作为参数,我可以将 ZipEntry 直接转换为 InputStream 并作为带有元数据的参数传递。我需要使用 EMR 来执行所有操作(本地文件系统不会出现在图片中)。我可以从 s3 读取 zip 文件并使用 EMR 解压缩文件并将其保存在 S3 上吗?
这是我的代码。
S3Object s3object = s3Client.getObject(new GetObjectRequest(bucketName,objName)); //sandip.zip
ZipInputStream in = new ZipInputStream(s3object.getObjectContent());
ZipEntry entry=in.getNextEntry(); // sandip_1.graphml
try {
while ((entry!= null)){
s3Client.putObject(bucketName, entry.getName(), new File(entry.getName()));
}
}
catch (IOException e) {
e.printStackTrace();
}
我当前的代码抛出以下异常。
Exception in thread "main" com.amazonaws.AmazonClientException: Unable to calculate MD5 hash: sandip_1.graphml (The system cannot find the file specified)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1319)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1273)
at com.example.testaws.test2.createAdjListZipFiles(Unknown Source)
at com.example.testaws.test1.main(test1.java:33)
Caused by: java.io.FileNotFoundException: sandip_1.graphml (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at com.amazonaws.util.Md5Utils.computeMD5Hash(Md5Utils.java:97)
at com.amazonaws.util.Md5Utils.md5AsBase64(Md5Utils.java:104)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1316)
... 3 more
请给我提示或参考。
【问题讨论】: