gpt4 book ai didi

java - GZIPOutputStream 是否已知会在压缩过程中丢失数据?

转载 作者:行者123 更新时间:2023-11-29 08:13:06 29 4
gpt4 key购买 nike

我对 GZIPOutputStream 有一个非常奇怪的问题压缩 double 组时。在第 57 个元素处,当我重新加载数据时出现了一个小差异:

57 > 3.003727492141554E7 3.0037273913440887E7
1900: false
57 > -6.110783629228158E7 -6.110783629076558E7
2000: false

1900 和 2000 是两组不同的 double 。左边的值是原来的值。

当我使用一个简单的 FileOutputStream没有 GZIP,我不明白这个问题。为什么? GZIP 输出流是否已知会丢失信息?

编辑

下面是我读取和写入数据的方式:

public static final double[] coefficients = new double[1161289];

...

public static void dump(File f) throws FileNotFoundException, IOException {

OutputStream os = FileUtils.zipContent(f);

byte[] ba = new byte[8];
ByteBuffer BF = ByteBuffer.wrap(ba);
BF.order(ByteOrder.BIG_ENDIAN);

for (int i=0;i<coefficients.length;i++) {
BF.putDouble(0, coefficients[i]);
os.write(ba,0,8);
}

os.close();

}

public static void load(File f) throws FileNotFoundException, IOException {

InputStream is = FileUtils.readZippedContent(f);

byte[] ba = new byte[8];
final ByteBuffer BF = ByteBuffer.wrap(ba);
BF.order(ByteOrder.BIG_ENDIAN);

for (int i=0;i<coefficients.length;i++) {
is.read(ba,0,8);
coefficients[i] = BF.getDouble(0);
}

}

...

public static GZIPOutputStream zipContent(File f)
throws FileNotFoundException, IOException {

return new GZIPOutputStream(new FileOutputStream(f));

}

public static GZIPInputStream readZippedContent(File f)
throws FileNotFoundException, IOException {

return new GZIPInputStream(new FileInputStream(f));

}

最佳答案

是什么让您认为:is.read(ba,0,8); 返回 8 总是

简而言之:阅读例程是伪造的。

关于java - GZIPOutputStream 是否已知会在压缩过程中丢失数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6719805/

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