java JDK 1.7 64位充气器抛出无效的代码长度集
在从JDK1.7 32位迁移到64位时,我们面临一个奇怪的问题。在我们的应用程序中,我们使用JDK Zip库压缩和解压缩字节[],并准备一个QR码(使用zxing)库。在JDK 1.7 32位上,一切运行正常,但在JDK 1.7上,充气失败,出现以下异常:
java.util.zip.DataFormatException: invalid code lengths set
at java.util.zip.Inflater.inflateBytes(Native Method)
at java.util.zip.Inflater.inflate(Inflater.java:259)
at java.util.zip.Inflater.inflate(Inflater.java:280)
在JDK 1.8 32位中也可以看到相同的行为
相关代码
public static byte[] compress(String s) {
Deflater comp = new Deflater();
comp.setInput(s.getBytes());
comp.finish();
ByteArrayOutputStream bos = new ByteArrayOutputStream(s.length());
byte[] buf = new byte[1024];
try {
while (!(comp.finished())) {
int count = comp.deflate(buf);
bos.write(buf, 0, count);
}
bos.close();
} catch (Exception e) {
}
byte[] compressedData = bos.toByteArray();
return compressedData;
}
public static byte[] decompress(byte[] b) {
Inflater decomp = new Inflater();
decomp.setInput(b);
ByteArrayOutputStream bos = new ByteArrayOutputStream(b.length);
byte[] buf = new byte[1024];
try {
while (!(decomp.finished())) {
int count = decomp.inflate(buf);
bos.write(buf, 0, count);
}
bos.close();
} catch (Exception e) {
e.printStackTrace();
}
byte[] decompressedData = bos.toByteArray();
return decompressedData;
}
非常感谢您的帮助
# 1 楼答案
compress方法正在捕获异常,但不记录它们。也许压缩也失败了,但是您没有注意到它,因为您没有记录日志