/**
* 对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. 00-python-常用命令

    1. pip 加速命令 pip install --index-url https://pypi.douban.com/simple 或者 pip install -i https://pypi.tu ...

  2. [C#]中获取当前程序运行路径的方法

    获取当前程序运行路径: ①//获取当前 Thread 的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集.string str = System.AppDomain.CurrentDoma ...

  3. [数据结构]P2.1 二叉搜索树

    二叉树就是每个节点最多有两个分叉的树.这里我们写一写一个典型的例子二叉搜索树,它存在的实际意义是什么呢? 在P1.1链表中,我们清楚了链表的优势是善于删除添加节点,但是其取值很慢:数组的优势是善于取值 ...

  4. Netflix分享构建Microservices的经验

    Netflix分享构建Microservices的经验 http://t.cn/Rwjgutw 新词:Microservices.我觉得就是service oriented architecture的 ...

  5. 『PyTorch x TensorFlow』第六弹_从最小二乘法看自动求导

    TensoFlow自动求导机制 『TensorFlow』第二弹_线性拟合&神经网络拟合_恰是故人归 下面做了三个简单尝试, 利用包含gradients.assign等tf函数直接构建图进行自动 ...

  6. NopCommerce 更改发票字体

    NopCommerce 默认是用~/App_Data/Pdf/FreeSerif.ttf 这个字体的. 用这个字体,发票里的中文不能显示. 可以把c:\windows\font\simhei.ttf  ...

  7. 各大型网站架构分析收集-原网址http://blog.csdn.net/lovingprince/article/details/3379710

    1. PlentyOfFish 网站架构学习http://www.dbanotes.net/arch/plentyoffish_arch.html 采取 Windows 技术路线的 Web 2.0 站 ...

  8. 跟随我在oracle学习php(4)

    制作html表单 客户端(每个用户的计算机)在浏览网页时,都会向服务器(后台)端索要数据,然后将得 到的数据呈现在浏览器当中.除了索要数据之外,有时客户端也希望能够向服务器端发送 一些数据. 这时我们 ...

  9. Jumpserver跳板机的搭建和部署

    1.需要搭云yum仓库wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo 2. ...

  10. Tomcat和java的安装

    java开发环境搭建1.将普通用户添加到sudoers中    进入root模式        编辑添加            visudo            username ALL=(ALL) ...