I have a .gz
file uploaded in the HDFS and I am trying to extract the contents of that file and put it into same directory of HDFS. This is the code I tried:
final String uri = "hdfs://localhost:8020/user/input1/output.gz";
Path pt=new Path(uri);
FileSystem fs = FileSystem.get(new Configuration());
Configuration conf = new Configuration();
CompressionCodecFactory factory = new CompressionCodecFactory(conf);
CompressionCodec codec = factory.getCodec(pt);
if(codec == null){
System.err.println("No Codec found !!!");
System.exit(1);
}
String outputUri = CompressionCodecFactory.removeSuffix(uri, codec.getDefaultExtension());
InputStream in = null;
OutputStream out = null;
try {
in = codec.createInputStream(fs.open(pt));
out = fs.create(new Path(outputUri));
} finally{
IOUtils.closeStream(in);
IOUtils.closeStream(out);
}
The file is getting extracted but the content is of 0 B
. Please advice where is the problem caused.