从 InflaterInputStream 读取数据而不膨胀 [英] Read data from InflaterInputStream without inflating

查看:31
本文介绍了从 InflaterInputStream 读取数据而不膨胀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个平面编码的数据流.Adler-32 检查要求数据采用 Big-Endian 形式,而我拥有的数据流采用 Little Endian 形式.

I have a data stream which is flate encoded. Adler-32 check requires the data to be in Big-Endian form whereas the data stream i have is in little endian form.

我尝试使用 Google-Guava 的 API

I tried using Google-Guava's API

 byte[] filedata=ByteStreams.toByteArray(inflaterInputStream);

因为我需要字节操作以防数据为小端格式.但是在将数据转换为字节数组的过程中,流会膨胀.因此抛出不正确的数据检查".

as i needed byte manipulation in case the data is in little-endian format. But during conversion of data to byte array , stream gets inflated. Hence "incorrect data check" is thrown.

那么如何在不膨胀数据的情况下从 InflaterInputstream 读取数据,然后在膨胀之前修改它,以便 Adler-32 检查通过,否则会引发数据完整性检查.

So How can i read data from InflaterInputstream without inflating the data and then modify it before inflating so that Adler-32 check passes otherwise it throws data integrity check.

我有一个类似的问题 在这里 Mark Adler 对此做出了回应,但我现在被困在上述问题上.

I have a similar question here to which Mark Adler had responded but i am now stuck at my above mentioned issue.

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);

推荐答案

来自 您链接到的问题,我知道您实际上遇到了不同的问题.你在那里声明 Adler 32 校验和是小端顺序,但应该是大端顺序.您还声明您已经设法反转校验和的字节顺序,并且对于大多数文件都可以正常工作.也就是说,您已经解决了您在此处描述的问题.但是您仍然有一些文件的校验和完全不正确.

From the question that you link to, I understand that you actually have a different problem. There you state that the Adler 32 checksum is in little-endian order, but is supposed to be in big-endian order. You also state that you already have managed to reverse the endianness of the checksum, and that that works fine with most files. That is, you have already solved the problem that you describe here. But you still have some files with totally incorrect checksums.

我同意马克·阿德勒本人在对该问题的评论中给出的建议:

I agree with the advice that Mark Adler himself gives in his comments to that question:

您需要告诉该 .dat 文件来自的任何人它错误.

You need to tell whoever that .dat file came from that it is wrong.

和:

您可以忽略错误并希望一切顺利.当 Adler-32检查不匹配,要么数据错误,Adler-32检查是错了,或者两者都有.没有办法知道哪个.

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.

这篇关于从 InflaterInputStream 读取数据而不膨胀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆