I'm new to hdfs/hadoop and need to know how to compress a file that is in a hdfs dir like hdfs://sandbox:8020/some/path.
I have tried
Path p = new Path("/my/path/test1.gz");
FSDataOutputStream os = fs.create(p);
GZIPOutputStream gzipOs = new GZIPOutputStream(new BufferedOutputStream(os));
Path filePath = file.getPath();
FSDataInputStream is = fs.open(filePath);
System.out.println("Writing gzip");
byte[] buffer = new byte[1024];
int len;
while((len= is.read(buffer)) != -1){
gzipOs.write(buffer, 0, len);
}
//close resources
is.close();
gzipOs.close();
But it doesn't work.
Any suggestions? Thanks in advance.