对数据进行GZIP压缩和解压
public class GzipUtils {
/**
* 对字符串进行gzip压缩
* @param data
* @return
* @throws IOException
*/
public static String compress(String data) throws IOException {
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");
}
/**
* 对字符串进行解压缩
* @param data
* @return
* @throws Exception
*/
public static String unCompress(String data) throws Exception {
if (null == data && data.length() <= 0) {
return data;
}
//创建一个新的byte数组输出流
ByteArrayOutputStream out = new ByteArrayOutputStream();
//创建一个byte数组输入流
ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes("ISO-8859-1"));
//创建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,通过解码字节将缓冲区内容转换为字符串
return out.toString("UTF-8");
}
Gzip压缩和解压数据代码
对数据进行GZIP压缩和解压的更多相关文章
- VB6进行GZIP解压&C#进行GZIP压缩和解压
VB进行GZIP解压的,DLL是系统的,如果没有 [点击下载] Option Explicit 'GZIP API '----------------------------------------- ...
- Gzip压缩和解压
/// <summary> /// 将传入字符串以GZip算法压缩后,返回Base64编码字符 /// </summary> /// <param name=" ...
- java GZIP压缩和解压
最近碰到了一个按GZIP解压指定的输入流数据,备份下 import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream ...
- C#对GZIP压缩和解压
/// <summary> /// 将Gzip的byte数组读取为字符串 /// </summary> /// <param name="bytes" ...
- C#实现通过Gzip来对数据进行压缩和解压
C#实现通过Gzip来对数据进行压缩和解压 internal static byte[] Compress(byte[] data) { using (var compressedStream = n ...
- 使用pako.js实现gzip的压缩和解压
poko.js可至Github下载:https://github.com/nodeca/pako 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...
- c#使用SharpZipLib对二进制数据进行压缩和解压
首先需要下载SharpZipLib,下载地址:http://icsharpcode.github.io/SharpZipLib/ 需要引入命名空间: using ICSharpCode.SharpZi ...
- [Swift通天遁地]七、数据与安全-(9)文件的压缩和解压
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Linux下tar bz gz等压缩包的压缩和解压
Linux下用户经常需要备份计算机系统中的数据,为了节省存储空间,常常将备份文件进行压缩,本文是对压缩和解压命令的大致总结 .tar.gz 解压:tar zxvf FileName.tar.gz ...
随机推荐
- 【LeetCode】Merge Sorted Array(合并两个有序数组)
这道题是LeetCode里的第88道题. 题目描述: 给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组. 说明: 初始化 nu ...
- 聊聊、Integer 封装特性
前几天在公司内部群,有人分享出了一道题,问谁能口算出来,他就膜拜那个人.题目如下: Class cache = Integer.class.getDeclaredClasses()[0]: Field ...
- 使用hibernate建立mysql连接以及生成映射类和配置文件*.cfg.xml
建立数据库连接 找到window—open perspective—myeclipse database explore空白出右键new注意 driver template 和driver class ...
- sqlserver导入dbf文件
select top 10000 * from OPENROWSET('MICROSOFT.JET.OLEDB.4.0','dBase IV;HDR=NO;IMEX=2;DATABASE=E:/日常/ ...
- 【转】超简单利用UGUI制作圆形小地图
http://sanwen.net/a/ithhtbo.html 由于UI都是Achor自己用PS做的,比较粗糙,大家见谅,不过丝毫不影响功能的实现,下面我们看看今天的笔记: 首先我们看看需要哪些组件 ...
- Apache+Openssl
Apache编译还需要一些依赖: #./configure --prefix……检查编辑环境时出现: checking for APR... no configure: error: APR not ...
- [暑假集训--数论]poj2909 Goldbach's Conjecture
For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 ...
- iOS中block 静态全局局部变量block变量,以及对象,详解!
//最近总是犯迷糊,关于block对外部变量的引用,今天有时间就写了一下,加深自己的理解,巩固基础知识 1 #import <Foundation/Foundation.h> ; int ...
- H5 基本标签使用 浅析 (含video标签、input表单等)
1. 音频标签<audio> <audio src = “./music/Alone.mp3” controls autoplay loop = “3” ></audio ...
- Document类
一.类结构 org.jsoup.nodes Class Document java.lang.Object org.jsoup.nodes.Node org.jsoup.nodes.Element o ...