/**
* 对data进行GZIP解压缩
* @param data
* @return
* @throws Exception
*/
public static String unCompress(byte[] data) throws Exception {
if (null == data && data.length <= 0) {
return null;
}
String reString = "";
try {
//创建一个新的byte数组输出流
ByteArrayOutputStream out = new ByteArrayOutputStream();
//创建一个byte数组输入流
ByteArrayInputStream in = new ByteArrayInputStream(data);
//创建gzip输入流
GZIPInputStream gzip = new GZIPInputStream(in);
byte[] buf = new byte[1024];
int len = 0;
while ((len = gzip.read(buf)) >= 0) {
out.write(buf, 0, len);
}
// 使用指定的 charsetName,通过解码字节将缓冲区内容转换为字符串
reString = out.toString("UTF-8");
out.close();
in.close();
gzip.close();
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return reString;
} /**
* 对字符串进行gzip压缩
* @param data
* @return
* @throws IOException
*/
public static String compress(String data) throws Exception {
if (null == data || data.length() <= 0) {
return data;
}
//创建一个新的byte数组输出流
ByteArrayOutputStream out = new ByteArrayOutputStream();
//使用默认缓冲区大小创建新的输出流
GZIPOutputStream gzip = new GZIPOutputStream(out);
//将b.length个字节写入此输出流
gzip.write(data.getBytes());
gzip.flush();
gzip.close(); //使用指定的charsetName,通过解码字节将缓冲区内容转换为字符串
return out.toString("ISO-8859-1");
}

对数据进行GZIP压缩或解压缩的更多相关文章

  1. GZIP压缩、解压缩工具类

    GZIP压缩.解压缩工具类: public class GZIPUtiles { public static String compress(String str) throws IOExceptio ...

  2. 对数据进行GZIP压缩和解压

    public class GzipUtils { /** * 对字符串进行gzip压缩 * @param data * @return * @throws IOException */ public ...

  3. GZip 压缩及解压缩

    /// <summary> /// GZipHelper /// </summary> public class GZipHelper { /// <summary> ...

  4. GZip压缩与解压缩

    GZIP的压缩与解压缩代码: public static class CompressionHelper { /// <summary> /// Compress the byte[] / ...

  5. java GZIP压缩与解压缩

    1.GZIP压缩 public static byte[] compress(String str, String encoding) { if (str == null || str.length( ...

  6. 将PHP程序中返回的JSON格式数据用gzip压缩输出

    //phpinfo(); 搜索下 zlib 是否开启 //此示例开启压缩 Content-Length:124 Size: 404B //未开启gzip压缩 Content-Length:675 Si ...

  7. 压缩与解压缩 gzip bzip2 tar 命令

    gzip压缩与解压缩 命令  gzip -v   解压缩 gzip-d 操作如下. 压缩 .可以看到源文件有5171大小,压缩后,变成了1998大小. 解压缩 .解压缩之后可以看到,原来的man_db ...

  8. Okhttp3请求网络开启Gzip压缩

    前沿 首先OkHttp3是支持Gzip解压缩的,不过我们要明白,它是支持我们在发起请求的时候自动加入header,Accept-Encoding: gzip,而我们的服务器返回的时候header中有C ...

  9. Java Web 减少网络 IO、静态资源磁盘 IO 有效的办法--响应使用 GZIP( 压缩http请求与响应gzip压缩)

    (转载http://blog.csdn.net/hylclxy/article/details/7779662) 出于节约流量考虑, 客户端在向服务端发送request的时候对post数据进行gzip ...

随机推荐

  1. 2018 ACM-ICPC, Syrian Collegiate Programming Contest

    2018 ACM-ICPC, Syrian Collegiate Programming Contest A Hello SCPC 2018! 水题 B Binary Hamming 水题 C Por ...

  2. PAT 1081 Rational Sum

    1081 Rational Sum (20 分)   Given N rational numbers in the form numerator/denominator, you are suppo ...

  3. struts2必备jar包(2.1.6版本)

    struts2必备jar包(2.1.6版本) struts2(2.1.6版本)必备的jar包有6个 struts2-core-2.1.6.jar freemarker-2.3.13.jar commo ...

  4. SpringCloud服务负载均衡实现原理02

  5. js中的setTimeout第三个参数

    setTimeout跟setInterval大家应该都很熟悉的,但是一直很少注意,原来这两个函数可以支持第三个参数的,但是IE就呵呵了,仅IE(6-9)呵呵了,其他浏览器都支持的。 第三个参数将作为回 ...

  6. Win10系列:C#应用控件基础12

    TextBlock控件 TextBlock控件是应用程序开发过程中经常使用的控件之一,它的主要功能是显示一段只读的文本内容.开发者可以使用TextBlock控件来显示提示信息,还可以根据需求将显示的提 ...

  7. day12_python_1124

    00 如何学习python 如何学好英语? 母系英语. 听 说 读 写 练 input output 听 说 读 写(练) 听,读 说 纠正 01 昨日内容回顾 生成器:本质就是迭代器,自己用pyth ...

  8. 201621123075作业07-Java GUI编程

    1. 本周学习总结 1.1 思维导图:Java图形界面总结 1.2 可选:使用常规方法总结其他上课内容. 2.书面作业 1. GUI中的事件处理 1.1 写出事件处理模型中最重要的几个关键词. 事件源 ...

  9. main 团队项目厨娘:用例图、类图、时序图

    团队:main 项目:厨娘 个人用例图

  10. STL的内存管理

    SGI STL 的内存管理 http://www.cnblogs.com/sld666666/archive/2010/07/01/1769448.html 1. 好多废话 在分析完nginx的内存池 ...