doubleの配列を圧縮するときに、 GZIPOutputStreamで非常に奇妙な問題が発生します。57番目の要素で、データをリロードすると小さな不一致が発生します。
57 > 3.003727492141554E7 3.0037273913440887E7
1900: false
57 > -6.110783629228158E7 -6.110783629076558E7
2000: false
1900と2000は、2つの異なるダブルのセットです。左の値は元の値です。
GZIPなしで単純なFileOutputStreamを使用すると、問題は発生しません。なんで?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));
}