import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class StrZipUtil {
/**
* @param input 需要压缩的字符串
* @return 压缩后的字符串
* @throws IOException IO
*/
public static String compress(String input) throws IOException {
if (input == null || input.length() == 0) {
return input;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzipOs = new GZIPOutputStream(out);
gzipOs.write(input.getBytes());
gzipOs.close();
return out.toString("ISO-8859-1");
}
/**
* @param zippedStr 压缩后的字符串
* @return 解压缩后的
* @throws IOException IO
*/
public static String uncompress(String zippedStr) throws IOException {
if (zippedStr == null || zippedStr.length() == 0) {
return zippedStr;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(zippedStr
.getBytes("ISO-8859-1"));
GZIPInputStream gzipIs = new GZIPInputStream(in);
byte[] buffer = new byte[256];
int n;
while ((n = gzipIs.read(buffer)) >= 0) {
out.write(buffer, 0, n);
}
// toString()使用平台默认编码,也可以显式的指定如toString("GBK")
return out.toString();
}
}
08-09 13:16:53.388 32248-32267/com.rustfisher.ndkproj D/rustApp: 开始存入数据库 ori1 len=304304 08-09 13:16:53.418 32248-32267/com.rustfisher.ndkproj D/rustApp: 已存入数据库 ori1 len=304304 , 耗时约37 ms 08-09 13:16:53.418 32248-32267/com.rustfisher.ndkproj D/rustApp: 开始压缩 ori1 len=304304 08-09 13:16:53.438 32248-32267/com.rustfisher.ndkproj D/rustApp: 压缩完毕 zip1 len=1112 , 耗时约19 ms 08-09 13:16:53.438 32248-32267/com.rustfisher.ndkproj D/rustApp: 存压缩后的数据进数据库 zip1.length=1112 08-09 13:16:53.448 32248-32267/com.rustfisher.ndkproj D/rustApp: 压缩后的数据已进数据库 zip1.length=1112 , 耗时约8 ms 08-09 13:16:53.448 32248-32267/com.rustfisher.ndkproj D/rustApp: 解压开始 08-09 13:16:53.488 32248-32267/com.rustfisher.ndkproj D/rustApp: 解压完毕 耗时约36 ms
08-09 10:38:42.759 23075-23109/com.rustfisher D/rustApp: 开始压缩 ori1 len=304304 08-09 10:38:42.764 23075-23109/com.rustfisher D/rustApp: 压缩完毕 zip1 len=1112 08-09 10:38:42.764 23075-23109/com.rustfisher D/rustApp: 解压开始 08-09 10:38:42.789 23075-23109/com.rustfisher D/rustApp: 解压完毕
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有