1, ZIP, GZIP computer file compression algorithm, JDK java.util.zip.* in the implementation. Mainly include Zipinputstream/zipoutputstream, Gzipinputstream/zipoutputstream.
2, Quicklz is known as the world's fastest compression library, and is also an open source compression library, which complies with the GPL 1, 2 or 3 protocol.
3, Snappy is a C + + compression and decompression of the development package, its goal is not to maximize compression, and incompatible with other compression formats. It is designed to provide high speed compression and reasonable compression rate. On the Core i7 processor in 64-bit mode, the compression speed of 250~500 MB per second is up. Widely used within Google, from BigTable to mapreduce and internal RPC systems.
4. LZF uses a hybrid encoding similar to LZ77 and LZSS for the string compression algorithm.
5, Jzlib is a pure Java open source decompression, compression package, and JDK zlib similar.
Introduction to pre-selection decompression class library use--zip
Compression
string s = "This is a string for testing";
Bytearrayoutputstream out = new Bytearrayoutputstream ();
Zipoutputstreamzout = new Zipoutputstream (out);
Zout.putnextentry (New ZipEntry ("0"));
Zout.write (S.getbytes ());
Zout.closeentry ();
byte[] Compressed = Out.tobytearray (); --Returns a byte array of the compressed string
Extract
Bytearrayoutputstream out = new Bytearrayoutputstream ();
Bytearrayinputstream in = new Bytearrayinputstream (compressed);
Zipinputstreamzin = new Zipinputstream (in);
Zin.getnextentry ();
byte[] buffer = new byte[1024];
Intoffset =-1;
while (offset = zin.read (buffer))! =-1) {
Out.write (buffer, 0, offset);
}
byte[] uncompressed = Out.tobytearray (); --Returns a byte array of the extracted string
Introduction to pre-selection decompression class library use--gzip
Compression
string s = "This is a string for testing";
Bytearrayoutputstream out = new Bytearrayoutputstream ();
Gzipoutputstream gout = new Gzipoutputstream (out);
Gout.write (S.getbytes ());
byte[] Compressed = Out.tobytearray (); --Returns a byte array of the compressed string
Extract
Bytearrayoutputstream out = new Bytearrayoutputstream ();
Bytearrayinputstream in = new Bytearrayinputstream (compressed);
Gzipinputstreamgzin =newgzipinputstream (in);
byte[] buffer = new byte[1024];
Intoffset =-1;
while (offset = gzin.read (buffer))! =-1) {
Out.write (buffer, 0, offset);
}
byte[] uncompressed = Out.tobytearray (); --Returns a byte array of the extracted string
Introduction to pre-selection decompression class library use--quicklz
Compression
string s = "This is a string for testing";
--level 1
Byte[] Compressed =quicklz.compress (S.getbytes (), 1); --Returns a byte array of the compressed string
--level3
Byte[] Compressed =quicklz.compress (S.getbytes (), 3); --Returns a byte array of the compressed string
Extract
Byte[] Uncompressed =quicklz.decompress (compressed); --Returns a byte array of the extracted string
Introduction to pre-selection decompression class library use--snappy
Compression
string s = "This is a string for testing";
Byte[] Compressed =snappy.compress (S.getbytes ()); --Returns a byte array of the compressed string
Extract
Byte[] Uncompressed =snappy.uncompress (compressed); --Returns a byte array of the extracted string
Introduction to the use of preselection decompression class library--LZF
Compression
string s = "This is a string for testing";
byte[] Compressed = Lzfencoder.encode (S.getbytes ()); --Returns a byte array of the compressed string
Extract
byte[] uncompressed = Lzfdecoder. Decode (compressed); --Returns a byte array of the extracted string
Introduction to the use of preselection decompression class library--Jzlib
Compression
string s = "This is a string for testing";
Bytearrayoutputstream out = new Bytearrayoutputstream ();
Deflateroutputstreamdout = new Deflateroutputstream (out);
Dout.write (S.getbytes ());
Dout.close (); --Need to close first
byte[] Compressed = Out.tobytearray (); --Returns a byte array of the compressed string
Extract
Bytearrayoutputstream out= new Bytearrayoutputstream ();
Bytearrayinputstream in = new Bytearrayinputstream (COMPRESSEDSTR);
Inflaterinputstream input = new Inflaterinputstream (in);
byte[] buffer = new byte[1024];
Intoffset =-1;
while (offset = input.read (buffer))! =-1) {
Out.write (buffer, 0, offset);
}
Out.close (); --Need to close first
byte[] uncompressed = Out.tobytearray (); --Returns a byte array of the extracted string
Transferred from: http://blog.csdn.net/mcpang/article/details/41141261
Introduction to the String Decompression class library (Zip, GZIP, Quicklz, Snappy, LZF, Jzlib)