/**
* 对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");
}

最新文章

  1. Javascript对象
  2. php 错误处理函数
  3. android原生ExpandableListView
  4. Repeater 根据某一列的值加颜色
  5. 安装logstash,elasticsearch,kibana三件套
  6. Windows线程漫谈界面线程和工作者线程
  7. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)
  8. JS设置cookie,删除cookie
  9. phpcms v9 源码解析(3)pc_base::creat_app()
  10. 《MFC游戏开发》笔记二 建立工程、调整窗口
  11. [LeetCode]LRU Cache有个问题,求大神解答【已解决】
  12. SQLite 约束
  13. git中添加多个SSH公钥,以及不同系统之间的差别
  14. Mysql innodb 间隙锁
  15. 迭代法与开根号求值(letcode 69)
  16. python 爬虫与数据可视化--matplotlib模块应用
  17. ES6躬行记(12)——数组
  18. C# Selenium 破解腾讯滑动验证
  19. SAP SQVI 快速浏览器
  20. 自学Zabbix11.6 Zabbix SNMP自定义OID

热门文章

  1. [MySQL]配置多个MySQL服务(Windows)
  2. 雷林鹏分享:jQuery EasyUI 数据网格 - 列运算
  3. npm2 与 npm3的包版本管理
  4. windows server2008 IIS搭建网站简易教程(阿里云)
  5. android ------ RecyclerView 模仿淘宝购物车
  6. Bilinear CNN与 Randomly Wired Neural Network
  7. mongoose手动生成ObjectId
  8. [uva P1601] The Morning after Halloween
  9. Vue.js 3.0 新特性预览
  10. sin n次方 x 的降幂公式