这是我在Android的压缩使用deflater数据代码如何计算字节大小deflater压缩输出的Android
String inputString = "kjhdf948w37fh4ifh34789fh34789fh3489fh7348fh84f8h4f3";
byte[] input = inputString.getBytes("UTF-8");
// Compress the bytes
byte[] output = new byte[100];
Deflater compresser = new Deflater(Deflater.BEST_COMPRESSION);
compresser.setInput(input);
compresser.finish();
int compressedDataLength = compresser.deflate(output);
现在我想修复“输出”字节数组的大小,我该怎么设置输出字节数组的大小。请帮我从这个问题出来。
byte[] output = new byte[100];
当前我设置了100我如何根据输入字节动态计算输出字节数组大小。
简单地说,你不能...做一些像'class TheData { public lenghtOfThisStructureInBytes;/* 4 + 4 +压缩数组长度*/public int lenghtOfTheDataBeforeCompression; byte [] theDataAfterCompression; }(我的假设是你wana把这个字节数组发送到某处 - 所以发送纯字节数组发送这个结构...现在fx:如果你使用套接字,你可以读取4个字节将它们转换为int(len),然后读取len - 4)字节,你会得到结构 – Selvin 2014-09-03 11:16:57