如何在 Java 中从 S3 读取 Snappy 压缩文件
How to read Snappy Compressed file from S3 in Java
目前我们在 Hadoop 中 运行 MapReduce 作业,其中输出被压缩到 SnappyCompression 中。然后我们将输出文件移动到 S3。现在我想通过 Java.
从 S3 读取压缩文件
我找到了从 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);
}
目前我们在 Hadoop 中 运行 MapReduce 作业,其中输出被压缩到 SnappyCompression 中。然后我们将输出文件移动到 S3。现在我想通过 Java.
从 S3 读取压缩文件我找到了从 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);
}