gpt4 book ai didi

java - JDK 1.7 64 位 Inflater 抛出无效的代码长度设置

转载 作者:行者123 更新时间:2023-12-01 06:14:39 25 4
gpt4 key购买 nike

从 JDK 1.7 32 位迁移到 64 位时,我们遇到了一个奇怪的问题。在我们的应用程序中,我们使用 JDK Zip 库来压缩和解压缩 byte[] 并准备 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;
}

非常感谢任何帮助。

最佳答案

您的压缩方法捕获异常但不记录它们。也许压缩也失败了,但你没有注意到它,因为你没有记录

关于java - JDK 1.7 64 位 Inflater 抛出无效的代码长度设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27621683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com