my dog learned polymorphism
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

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 Corrupt GZIP trailer
1162 [Thread-0] DEBUG util.GZipUtil - Corrupt GZIP trailer
1162 [Thread-0] INFO LoggingTask - unzippedFile - c:\aaa\logs\1098035357042.log
at Source)
at Source)
at Source)
at com.patronsolutions.messaging.util.GZipUtil.unzip(
at java.util.TimerThread.mainLoop(Unknown Source)
at 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:

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
Roman Smolkin

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

Joined: Oct 27, 2005
Posts: 20271

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

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Corrupt GZIP trailer
jQuery in Action, 3rd edition