附加的代码抛出java.util.zip.ZipException:给定的.dat文件的数据检查不正确 [英] Attached code throws java.util.zip.ZipException: incorrect data check for given .dat file
问题描述
我有一个用flate编码的dat文件. 我正在尝试使用基于ZLib库的InflateInputStream对该文件进行解码. 但是使用下面的示例可以给我
I have a dat file which is encoded using flate. I am trying to decode that file using InflateInputStream which is based on ZLib library. But using the below sample gives me
Exception in thread "main" java.util.zip.ZipException: incorrect data check
.dat文件保留在此处
The .dat file is kept here
代码:-
int buflength = 1;
byte[] buf = new byte[buflength];
FileInputStream is = new FileInputStream(new File(INPUT_DIRECTORY + INPUT_FILE));
Inflater decompresser = new Inflater();
//decompresser.setInput(buf);
InflaterInputStream ifis = new InflaterInputStream(is,decompresser,buflength);
FileOutputStream os = new FileOutputStream(new File(OUTPUT_DIRECTORY + OUTPUT_FILE));
/*Deflater compressor = new Deflater();
DeflaterOutputStream dfos = new DeflaterOutputStream(os, compressor, buflength);
*/
int counter = 0;
//long bytesToCopy = 40000;
int bytesThisRead = 0;
long bytesCopied = 0;
while ((bytesThisRead = ifis.read(buf, 0, buf.length)) != -1)
{
os.write(buf, 0, bytesThisRead);
System.out.println((counter++) + " " + bytesThisRead);
//bytesToCopy -= bytesThisRead;
bytesCopied += bytesThisRead;
}
我尝试调试InflatterInputStream库中的代码,在那里我发现读取原始数据流中的最后一个字节存在一些问题. (将buf大小保持为1,然后在最后一个字节之后出现错误)
I tried debugging the code in InflatterInputStream library, there i could find that there is some issue with reading the last byte in the raw data stream. (keep buf size as 1 then error comes after last byte)
在此数据文件中,原始流的大小为11005瓦,解码后的流的大小为36963.
Here for this data file , size of the raw stream is 11005 wheras for decoded stream is 36963.
那么如何解决最后一个字节损坏的问题呢?
So how to fix such issues in which last byte is corrupt?
推荐答案
创建zlib流(UL_obj_11_0_raw.dat)的人没有创建zlib流.最后,Adler-32支票应该以大端顺序存储,但是他们以错误的顺序(小端顺序)存储了正确的支票值.
Whoever made that zlib stream (UL_obj_11_0_raw.dat) did not make a zlib stream. The Adler-32 check at the end is supposed to be stored in big-endian order, but they stored the correct check value in the wrong order, little-endian.
这篇关于附加的代码抛出java.util.zip.ZipException:给定的.dat文件的数据检查不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!