aspose file tools*
The moose likes Java in General and the fly likes Corrupt GZIP trailer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Corrupt GZIP trailer " Watch "Corrupt GZIP trailer " New topic
Author

Corrupt GZIP trailer

Karen Gomes
Ranch Hand

Joined: Aug 25, 2003
Posts: 60
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:




Thanks
Karen
Ajith Anand
Ranch Hand

Joined: Aug 30, 2004
Posts: 40
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
[url]www.lxisoft.com[/url]
Roman Smolkin
Greenhorn

Joined: Feb 09, 2011
Posts: 1
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...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

Neither Karen nor Ajith has been active for years, so I doubt you will get an answer from them.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: Corrupt GZIP trailer