资源简介
两种方法 对字符串进行压缩和解压缩,inflater和deflater。

代码片段和文件信息
package com.bonc.zip;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
/**
* Deflater和Inflater压缩解压缩方式
* @author Administrator
*
*/
public class CommonUtils {
//压缩
public static byte[] compress(String s) throws IOException DataFormatException {
byte[] input = s.getBytes(“UTF-8“);
Deflater compressor = new Deflater();
compressor.setLevel(9);
compressor.setInput(input);
compressor.finish();
ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
byte[] buf = new byte[1024];
int len = 0;
while (!compressor.finished()) {
len = compressor.deflate(buf);
bos.write(buf 0 len);
}
bos.close();
return bos.toByteArray();
}
//解压缩
public static String decompress(byte[] compressData)
throws IOException DataFormatException
{
Inflater decompressor = new Inflater();
decompressor.setInput(compressData);
ByteArrayOutputStream bos = new ByteArrayOutputStream(compressData.length);
byte[] buf = new byte[1024];
int len = 0;
while (!decompressor.finished()) {
len = decompressor.inflate(buf);
bos.write(buf 0 len);
}
bos.close();
return new String(bos.toByteArray());
}
public static void main(String[] args) {
try {
System.out.println(decompress(compress(“ddcdfcdsssdad“)));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DataFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 232 2012-12-28 15:37 ZipTest\.classpath
文件 383 2012-12-31 09:10 ZipTest\.project
文件 2086 2012-12-31 09:11 ZipTest\bin\com\bonc\zip\CommonUtils.class
文件 1940 2012-12-31 09:12 ZipTest\bin\com\bonc\zip\ZipUtils.class
文件 1740 2012-12-31 09:11 ZipTest\src\com\bonc\zip\CommonUtils.java
文件 1641 2012-12-31 09:12 ZipTest\src\com\bonc\zip\ZipUtils.java
目录 0 2013-01-05 13:47 ZipTest\bin\com\bonc\zip
目录 0 2013-01-05 13:47 ZipTest\src\com\bonc\zip
目录 0 2013-01-05 13:47 ZipTest\bin\com\bonc
目录 0 2013-01-05 13:47 ZipTest\src\com\bonc
目录 0 2013-01-05 13:47 ZipTest\bin\com
目录 0 2013-01-05 13:47 ZipTest\src\com
目录 0 2013-01-05 13:47 ZipTest\bin
目录 0 2013-01-05 13:47 ZipTest\src
目录 0 2013-01-05 13:47 ZipTest
----------- --------- ---------- ----- ----
8022 15
相关资源
- CoreUIVue是基于Bootstrap4的免费Vue管理模
- SpringBoot+H2+mybatis-plus59130
- 登录注册界面.zip48872
- 数字华容道
- SSM+Shiro+redis实现单点登陆
- jstl-api-1.2和jstl-impl-1.2
- 基于MVC模式的会员管理系统
- 国内一家大型软件公司内部的正规软
- 仿windows记事本
- GUI银行管理系统
- 超市收银系统eclipse access大学课程设计
- 模拟ATM柜员机系统--连接数据库
- A*算法的2D演示(带源码)
- 代码审查表和代码审查实例
- 仿126 网易 163 邮箱 界面
- Tomcat6.x
- 简单的行编辑器
- 扫雷(MVC架构)
- 302 Found
- window ping命令加时间并记录日志
- springboot+rabbitmq项目demo(亲测可正常运
- jxbrowser 所有版本通用的破解包
- 2017年-传智播客-张志君老师-SpringBoo
- Blob.js+Export2Excel.js
- 机会路由源代码+仿真工具(SCORP)
- POI中文帮助文档附带api手册.zip
- 2018双十一阿里供应链服务平台讲座
- 原银在线信贷平台概要设计说明书v
- office_word_api 开发文档
- sun.misc.Unsafe源码
评论
共有 条评论