5,392
社区成员
发帖
与我相关
我的任务
分享
public static byte[] zlibCompress(String message)throws Exception
{
String chatacter="UTF-8";
byte[] input = message.getBytes(chatacter);
System.out.println("input length "+input.length);
byte[] output = new byte[input.length+10+new Double(Math.ceil(input.length*0.25f)).intValue()];
System.out.println(output.length);
Deflater compresser = new Deflater();
compresser.setInput(input);
compresser.finish();
int compressedDataLength = compresser.deflate(output);
System.out.println("compressedDataLength "+compressedDataLength);
compresser.end();
//String ostr=new String(output,0,compressedDataLength,chatacter);
//System.out.println("out str "+ostr);
return Arrays.copyOf(output, compressedDataLength);
}