zoukankan      html  css  js  c++  java
  • 字符串解压缩类库(zip、GZIP、QuickLz、snappy、lzf、jzlib)介绍

    1、ZIP、 GZIP  计算机文件压缩算法,JDK中java.util.zip.*中实现。主要包括ZipInputStream/ ZipOutputStream、GZipInputStream/ZipOutputStream。

    2、QuickLZ是一个号称世界压缩速度最快的压缩库,并且也是个开源的压缩库,其遵守 GPL 1, 2 或 3协议。

    3、Snappy是一个 C++的用来压缩和解压缩的开发包,其目标不是最大限度压缩,而且不兼容其他压缩格式。旨在提供高速压缩速度和合理的压缩率。在64位模式的 Core i7 处理器上,可达每秒250~500兆的压缩速度。在 Google 内部被广泛的使用,从 BigTable到 MapReduce以及内部的RPC 系统。

    4、LZF采用类似lz77和lzss的混合编码,针对字符串压缩算法。 

    5、JZLIB是纯java的开源解压、压缩包,与JDK中ZLIB类似。

    预选解压缩类库使用介绍--ZIP

    压缩

    String  s = “这是一个用于测试的字符串”;

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    ZipOutputStreamzout = new ZipOutputStream(out);

    zout.putNextEntry(new ZipEntry("0"));

    zout.write(s.getBytes());

    zout.closeEntry();

    byte[] compressed = out.toByteArray();   --返回压缩后的字符串的字节数组

    解压

    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();   --返回解压缩后的字符串的字节数组

    预选解压缩类库使用介绍--GZIP

    压缩

    String  s = “这是一个用于测试的字符串”;

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    GZipOutputStream gout = new GZipOutputStream(out);

    gout.write(s.getBytes());

    byte[] compressed = out.toByteArray();   --返回压缩后的字符串的字节数组

    解压

    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();   --返回解压缩后的字符串的字节数组

    预选解压缩类库使用介绍--QuickLZ

    压缩

    String  s = “这是一个用于测试的字符串”;

    --Level 1

    byte[] compressed =QuickLZ.compress(s.getBytes(), 1);   --返回压缩后的字符串的字节数组

    --Level3

    byte[] compressed =QuickLZ.compress(s.getBytes(), 3);   --返回压缩后的字符串的字节数组

    解压

    byte[] uncompressed =QuickLZ.decompress(compressed );   --返回解压缩后的字符串的字节数组

    预选解压缩类库使用介绍--Snappy

    压缩

    String  s = “这是一个用于测试的字符串”;

    byte[] compressed =Snappy.compress(s.getBytes());   --返回压缩后的字符串的字节数组

    解压

    byte[] uncompressed =Snappy.uncompress(compressed );   --返回解压缩后的字符串的字节数组

    预选解压缩类库使用介绍-- LZF

    压缩

    String  s = “这是一个用于测试的字符串”;

    byte[] compressed = LZFEncoder.encode(s.getBytes());   --返回压缩后的字符串的字节数组

    解压

    byte[] uncompressed = LZFDecoder.decode(compressed );   --返回解压缩后的字符串的字节数组

    预选解压缩类库使用介绍-- JZLIB

    压缩

    String  s = “这是一个用于测试的字符串”;

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    DeflaterOutputStreamdout = new DeflaterOutputStream(out);

    dout.write(s.getBytes());

    dout.close();         --需要先关闭

    byte[] compressed = out.toByteArray();   --返回压缩后的字符串的字节数组

    解压

    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();   --需要先关闭

    byte[] uncompressed = out.toByteArray();   --返回解压缩后的字符串的字节数组

    转自:http://blog.csdn.net/mcpang/article/details/41141261

  • 相关阅读:
    位置控制
    Scaleform结合C++编程
    使用定点缓存进行绘制
    纹理
    动态规划:背包问题
    希尔排序
    折半插入排序
    快速排序
    上楼梯算法
    归并排序
  • 原文地址:https://www.cnblogs.com/maxiaodoubao/p/4682622.html
Copyright © 2011-2022 走看看