日期:2014-05-18 浏览次数:20987 次
public static String gzip(String primStr) {
if (primStr == null || primStr.length() == 0) {
return primStr;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip=null;
try {
gzip = new GZIPOutputStream(out);
gzip.write(primStr.getBytes());
} catch (IOException e) {
e.printStackTrace();
}finally{
if(gzip!=null){
try {
gzip.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return new sun.misc.BASE64Encoder().encode(out.toByteArray());
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String t = "sdfl*^#*%)}{OFAESKJ";
System.out.println("源长度:" + t.length());
String t3 = ZipUtils.gzip(t);
System.out.println("压缩后字符串:" + t3);
System.out.println("压缩后长度:" + t3.length());
}