Reputation: 2089
I have a java app which generates an output file, and that needs to be compressed. Currently, I am zipping it after the file has been generated using script
$ zip <abc.zip> abc
Other option is to let Java code compress it using below classes.
java.util.zip.ZipEntry;
java.util.zip.ZipOutputStream;
Now, want to know which is better in terms of compression ratio and time taken ?
Java has advantage of being system independent, but that is ok for me.
Upvotes: 2
Views: 2024
Reputation: 35068
I would think that you may get a few advantages by wrapping the output stream that writes your file with a ZipOutputStream
.
Using the script there are several things that you would need to do that you can avoid by writing the zipped stream directly:
Whereas if you use the ZipOutputStream
zip
script. zip
is available on your deployment platform, here I've got it on Linux but not on AIX)As always, the solution is to prototype it and carry out testing and then decide which performance/compression is better/acceptable.
Upvotes: 0
Reputation: 12064
I think performance will be same but using
zip -9 <abc.zip> abc
you can get more compression and you can avoid recursing directory in java by giving -r
switch in zip command
Upvotes: 1
Reputation: 417
i think of course Java is slower, because it is running on the JVM, and not directly to the OS,. if i were you, i will keep using that script, as long as i have the time to execute it myself,. i think that is better if you automate it, if you may have no time to execute them everytime,.
Upvotes: -1
Reputation: 10352
Java's ZipOutputStream uses the same zlib which is used by zip command as a native library. So in terms of performance they should be equivalent.
Upvotes: 3