首页 > 代码库 > JAVA代码之Snappy 压缩
JAVA代码之Snappy 压缩
Snappy is a compression/decompression library. It does not aim for maximum compression, or compatibility with any other compression library; instead, it aims for very high speeds and reasonable compression. For instance, compared to the fastest mode of zlib, Snappy is an order of magnitude faster for most inputs, but the resulting compressed files are anywhere from 20% to 100% bigger. On a single core of a Core i7 processor in 64-bit mode, Snappy compresses at about 250 MB/sec or more and decompresses at about 500 MB/sec or more.
Snappy is widely used inside Google, in everything from BigTable and MapReduce to our internal RPC systems. (Snappy has previously been referred to as “Zippy” in some presentations and the likes.)
Snappy 是Google的一个 C++ 的用来压缩和解压缩的开发包。其目标不是最大限度压缩或者兼容其他压缩格式,而是旨在提供高速压缩速度和合理的压缩率。Snappy 比 zlib 更快,但文件相对要大 20% 到 100%。在 64位模式的 Core i7 处理器上,可达每秒 250~500兆的压缩速度。
snappy 的前身是Zippy。虽然只是一个数据压缩库,它却被Google用于许多内部项目程,其中就包括BigTable,MapReduce和RPC。Google宣称它在这个库本身及其算法做了数据处理速度上的优化,作为代价,并没有考虑输出大小以及和其他类似工具的兼容性问题。Snappy特地为64位x86处理器做了优化,在单个Intel Core i7处理器内核上能够达到至少每秒250MB的压缩速率和每秒500MB的解压速率。
Google极力赞扬Snappy的各种优点,Snappy下载从一开始就被“设计为即便遇到损坏或者恶意的输入文件都不会崩溃”,而且被Google在生产环境中用于压缩PB级的数据。其健壮性和稳定程度可见一斑。
核心代码下载:
package cn.com.kafkademo.kafkademo;
import java.io.IOException;
import org.xerial.snappy.Snappy;
public class SnappyDemo {
/**
* args
*/
public static void main(String[] args) {
}
public static byte[] compressHtml(String html) {
try {
return Snappy.compress(html.getBytes("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static String decompressHtml(byte[] bytes) {
try {
return new String(Snappy.uncompress(bytes));
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
下载
JAVA代码之Snappy 压缩