问题
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.
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.
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.
I have a similar question here to which Mark Adler had responded but i am now stuck at my above mentioned issue.
EDIT:
The inflaterInputStream
is created this way:
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);
回答1:
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:
You need to tell whoever that .dat file came from that it is wrong.
and:
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.
来源:https://stackoverflow.com/questions/33496869/read-data-from-inflaterinputstream-without-inflating