I'm trying to convert a log file to a gzip file, and another application will unzip the file to a log file. I have attached my class that does so below. This is the error I get :
------------------------------ 1132 [Thread-0] INFO util.GZipUtil - in unzip func 1132 [Thread-0] INFO util.GZipUtil - input file name = 1098035357042.gzip 1132 [Thread-0] INFO util.GZipUtil - output file name = c:\aaa\logs\1098035357042.log 1162 [Thread-0] INFO util.GZipUtil - (int)file.length() = 105 java.io.IOException: Corrupt GZIP trailer 1162 [Thread-0] DEBUG util.GZipUtil - java.io.IOException: Corrupt GZIP trailer 1162 [Thread-0] INFO LoggingTask - unzippedFile - c:\aaa\logs\1098035357042.log at java.util.zip.GZIPInputStream.readTrailer(Unknown Source) at java.util.zip.GZIPInputStream.read(Unknown Source) at java.io.FilterInputStream.read(Unknown Source) at com.patronsolutions.messaging.util.GZipUtil.unzip(GZipUtil.java:108) at LoggingTask.run(LogGateLinkInfo.java:131) at java.util.TimerThread.mainLoop(Unknown Source) at java.util.TimerThread.run(Unknown Source) V10/1/20042:32:23 PMPARKGATE A110180060033846ERUD CODE-10110331221True
I did find a bug that says that the gzip has a bug if the inflated file size is >2GB then we get the above exception. In my case I get it even when the file size is 89 bytes. Also my data get altered after I have unzipped it. Data before zipping: V10/1/20042:32:23 PMPARKGATE A110180060033846BUD CODE-11110031221True
Data after unzipping: V10/1/20042:32:23 PMPARKGATE A110180060033846ERUD CODE-10110331221True
Can anyone help me out with this? Should I use gzip or zip for this? How does one decide which one to use? I read that the zip(not gzip) also has a bug in java. What does this "Corrupt GZIP trailer" mean?
Here is my code:
Joined: Aug 30, 2004
I'm afraid there is something in your program which you should give a second thought:
when you say byte buf = new byte[(int)file.length()];
casting the file length to int , there are chances that you corrupt the stream for file sizes which are greater than 2148 MB , I think you will run into stream corruption in these cases....
LXI Technologies P Ltd
Joined: Feb 09, 2011
Hi, did you ever figure out a solution? I'm running into very similar issue (same error) but in a slightly different scenario...
I'm not even writing anything to file, just create the input and output streams and then send it back...