There are standard compression utilities in java: java.util.zip is a general-purpose library, but due to its clean availability, this is a good solution. Specialized compression, coding should be investigated if necessary, and I rarely recommend zip as a choice for selection.
Here is an example of how to handle zip through Deflater/Inflater . Most people know ZipInput / Output Stream (and especially Gzip). All of them have recessions when processing copies from mem-> zlib and esp. GZip, which is a complete disaster, since CRC32 calls its own code (calling its own code eliminates the possibility of optimization and introduces a few more calls to performance).
A few important points: do not increase the ZIP compression, which can lead to any performance - of course, you can experiment and match their best ratio between the activity of the processor and the disk.
The code also demonstrates one of the real flaws of java.util.zip - it does not support direct buffers. Support is trivial, but no one bothers her. Direct buffers will save multiple copies of memory and reduce memory footprint.
Last note: there is a java version of (j) zlib , and it surpasses its own impl. compression is pretty nice.
package t1; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.Random; import java.util.zip.DataFormatException; import java.util.zip.Deflater; import java.util.zip.Inflater; public class ZInt { private static final int bucketSize = 1<<17;
Please note that the code is not a suitable standard!
Delayed answers arise due to the fact that it was rather boring to code, another zip example, sorry
bestsss
source share