在不膨胀的情况下从 InflaterInputStream 读取数据
Read data from InflaterInputStream without inflating
我有一个平面编码的数据流。
Adler-32 检查要求数据采用大端形式,而我拥有的数据流采用小端形式。
我尝试使用 Google-Guava 的 API
byte[] filedata=ByteStreams.toByteArray(inflaterInputStream);
因为我需要字节操作以防数据是小端格式。
但是在将数据转换为字节数组的过程中,流会膨胀。因此 "incorrect data check" 被抛出。
那么我如何在不膨胀数据的情况下从 InflaterInputstream 读取数据,然后在膨胀之前修改它,以便 Adler-32 检查通过,否则它会抛出数据完整性检查。
我有一个类似的问题 ,Mark Adler 已经回答过,但我现在被困在上面提到的问题上。
编辑:
inflaterInputStream
是这样创建的:
int buflength = 4096;
byte[] buf = new byte[buflength];
FileInputStream is = new FileInputStream(new File(filePath));
Inflater decompresser = new Inflater();
InflaterInputStream inflatterInputStream = new InflaterInputStream(is,decompresser,buflength);
根据 ,我了解到您实际上遇到了不同的问题。在那里你声明阿德勒 32 校验和是小端顺序,但应该是大端顺序。您还声明您已经设法反转校验和的字节顺序,并且这对大多数文件都适用。也就是说,您已经解决了此处描述的问题。但是您仍然有一些文件的校验和完全不正确。
我同意马克阿德勒本人在他对这个问题的评论中给出的建议:
You need to tell whoever that .dat file came from that it is wrong.
和:
You could ignore the error and hope for the best. When the Adler-32
check does not match, either the data is wrong, the Adler-32 check is
wrong, or both. There is no way to know which.
我有一个平面编码的数据流。 Adler-32 检查要求数据采用大端形式,而我拥有的数据流采用小端形式。
我尝试使用 Google-Guava 的 API
byte[] filedata=ByteStreams.toByteArray(inflaterInputStream);
因为我需要字节操作以防数据是小端格式。 但是在将数据转换为字节数组的过程中,流会膨胀。因此 "incorrect data check" 被抛出。
那么我如何在不膨胀数据的情况下从 InflaterInputstream 读取数据,然后在膨胀之前修改它,以便 Adler-32 检查通过,否则它会抛出数据完整性检查。
我有一个类似的问题
编辑:
inflaterInputStream
是这样创建的:
int buflength = 4096;
byte[] buf = new byte[buflength];
FileInputStream is = new FileInputStream(new File(filePath));
Inflater decompresser = new Inflater();
InflaterInputStream inflatterInputStream = new InflaterInputStream(is,decompresser,buflength);
根据
我同意马克阿德勒本人在他对这个问题的评论中给出的建议:
You need to tell whoever that .dat file came from that it is wrong.
和:
You could ignore the error and hope for the best. When the Adler-32 check does not match, either the data is wrong, the Adler-32 check is wrong, or both. There is no way to know which.