简体   繁体   English

如何在Java中从S3读取Snappy压缩文件

[英]How to read Snappy Compressed file from S3 in Java

Currently we are running MapReduce job in Hadoop in which the output is compressed into SnappyCompression. 当前,我们正在Hadoop中运行MapReduce作业,其中输出被压缩到SnappyCompression中。 Then we are moving the output file to S3. 然后我们将输出文件移至S3。 Now I want to read the Compressed file from S3 through Java. 现在,我想通过Java从S3读取压缩文件。

I found the answer to read snappy compressed file from S3. 我找到了从S3读取快速压缩文件的答案。 First you should get the object content from S3. 首先,您应该从S3获取对象内容。 And then decompress the file. 然后解压缩文件。

    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);
    }   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM