1

目前我们正在 Hadoop 中运行 MapReduce 作业,其中输出被压缩为 SnappyCompression。然后我们将输出文件移动到 S3。现在我想通过 Java 从 S3 读取压缩文件。

4

1 回答 1

1

我找到了从 S3 读取 snappy 压缩文件的答案。首先,您应该从 S3 获取对象内容。然后解压文件。

    S3Object s3object = s3Client.getObject(new GetObjectRequest(bucketName,Path));
    InputStream inContent = s3object.getObjectContent();
    CompressionCodec codec = (CompressionCodec) ReflectionUtils.newInstance(SnappyCodec.class, new Configuration());
    InputStream inStream = codec.createInputStream(new BufferedInputStream(inContent));
    InputStreamReader  inRead = new InputStreamReader(inStream);
    BufferedReader br = new BufferedReader(inRead);
    String line=null;
    while ((line = br.readLine()) != null){
        system.out.println(line);
    }   
于 2015-05-04T11:37:53.850 回答