I was using FileChannel and FileInputStream to do a simple file copying from File fromFile to File toFile.
The code is basically like this:
source = new FileInputStream(fromFile).getChannel();
destination = new FileOutputStream(toFile, false).getChannel(); // overwrite
destination.transferFrom(source, 0, source.size());
where fromFile and toFile are proper File objects.
Now, instead of copying from fromFile directly, i wanted to compress its content using GZIP (found in Java libraries) and then copy to toFile. Also reversely, when I transfer back from toFile, I would like to decompress it as well.
I was wondering is there a simple way like
source = new GZIPCompressInputStream(new FileInputStream(fromFile)).getChannel();
or
source = new GZIPDecompressInputStream(new FileInputStream(fromFile)).getChannel();
and all the rest of code remain unchanged. Do you have any suggestion on the cleanest solution to this?
Thanks..