我压缩采用pako.js
js压缩代码: function compressStr() {
var sstr = '我是未压缩的字符串';
sstr = decodeURIComponent(encodeURIComponent(sstr));
var cpredString = pako.deflate(sstr,{to:'string'});
return cpredString;
}
我的java解压缩代码
public static byte[] decompressStrToBytes(String instr) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(instr.getBytes("utf-8"));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
InflaterInputStream iis = new InflaterInputStream(bis, new Inflater(true));
int readCount = 0;
byte[] buf = new byte[1024];
try {
while ((readCount = iis.read(buf, 0, buf.length)) > 0) {
bos.write(buf, 0, readCount);
}
iis.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
return bos.toByteArray();
}
前端数据可以正确交给服务端,服务端无法正确解压,错误:invalid stored block lengths
请教各位大神。
把压缩的字符串toByte下传入下述方法试下呢
public static byte[] decompress(byte[] value) throws DataFormatException {
ByteArrayOutputStream bos = new ByteArrayOutputStream(value.length);
Inflater decompressor = new Inflater();
try {
decompressor.setInput(value);
final byte[] buf = new byte[1024];
while (!decompressor.finished()) {
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
}
} finally {
decompressor.end();
}
return bos.toByteArray();
}
}
deviine007,感谢你参与我的提问,您说的已字节做参数,和以string做参数,是一样的,不行
过去半年的问题了,现在解决了吗?CSND的问答大富翁游戏的搜索功能太不合理了,搜索出的问题都回答过一遍了。