对数据进行GZIP压缩或解压缩
/**
* 对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压缩或解压缩的更多相关文章
- GZIP压缩、解压缩工具类
GZIP压缩.解压缩工具类: public class GZIPUtiles { public static String compress(String str) throws IOExceptio ...
- 对数据进行GZIP压缩和解压
public class GzipUtils { /** * 对字符串进行gzip压缩 * @param data * @return * @throws IOException */ public ...
- GZip 压缩及解压缩
/// <summary> /// GZipHelper /// </summary> public class GZipHelper { /// <summary> ...
- GZip压缩与解压缩
GZIP的压缩与解压缩代码: public static class CompressionHelper { /// <summary> /// Compress the byte[] / ...
- java GZIP压缩与解压缩
1.GZIP压缩 public static byte[] compress(String str, String encoding) { if (str == null || str.length( ...
- 将PHP程序中返回的JSON格式数据用gzip压缩输出
//phpinfo(); 搜索下 zlib 是否开启 //此示例开启压缩 Content-Length:124 Size: 404B //未开启gzip压缩 Content-Length:675 Si ...
- 压缩与解压缩 gzip bzip2 tar 命令
gzip压缩与解压缩 命令 gzip -v 解压缩 gzip-d 操作如下. 压缩 .可以看到源文件有5171大小,压缩后,变成了1998大小. 解压缩 .解压缩之后可以看到,原来的man_db ...
- Okhttp3请求网络开启Gzip压缩
前沿 首先OkHttp3是支持Gzip解压缩的,不过我们要明白,它是支持我们在发起请求的时候自动加入header,Accept-Encoding: gzip,而我们的服务器返回的时候header中有C ...
- Java Web 减少网络 IO、静态资源磁盘 IO 有效的办法--响应使用 GZIP( 压缩http请求与响应gzip压缩)
(转载http://blog.csdn.net/hylclxy/article/details/7779662) 出于节约流量考虑, 客户端在向服务端发送request的时候对post数据进行gzip ...
随机推荐
- [Spring MVC] 取控制器返回的ModelAndView/Map/Model/Request的对象
${key }页面可取, <input value="${key}"> 或者<%=request.getParameter("key")%&g ...
- 文献导读 | A Pan-Cancer Analysis of Enhancer Expression in Nearly 9000 Patient Samples
Chen, H., Li, C., Peng, X., Zhou, Z., Weinstein, J.N., Liang, H. and Cancer Genome Atlas Research Ne ...
- 20190227xlVBA辅助输入
Dim tg As Range Dim FreeInput As Boolean Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.Retur ...
- 范式及其在mysql数据库设计中的应用
一.什么是范式 1.1.范式:Normal Format,是离散数学的知识,是为了解决数据的存储与优化而提出来的.要求存储数据后,凡是能够通过关系寻找出来的数据,坚决不再重复存储,终极目标是为了减少数 ...
- React文档(八)条件渲染
在React中,你可以创建不同的组件各自封装你需要的东西.之后你可以只渲染其中的一部分,这取决于应用的state(状态). 条件渲染在React里就和js里的条件语句一样.使用js里的if或者条件表达 ...
- @ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常
@ControllerAdvice 和 @ExceptionHandler 的区别 ExceptionHandler, 方法注解, 作用于 Controller 级别. ExceptionHandle ...
- c# 转换成时间类型
if (rngFound.Value.ToString().Contains("/")) { closingdate = rngFound.Value; } else if (rn ...
- prefixspan python
from:https://github.com/chuanconggao/PrefixSpan-py API Usage Alternatively, you can use the algorith ...
- eXosip sip
eXosip是对osip的封装,是对sip协议的使用更简单.osip是gnu开源的sip协议实现. 介绍: http://savannah.nongnu.org/projects/exosip 下载地 ...
- layer中每次用到都要查来查去的功能
1.关闭当前弹出层 var index = parent.layer.getFrameIndex(window.name); setTimeout(function(){parent.layer.cl ...