As with all of these types of problems when an error occurs, try to do fewer things at once. So in your case:
Firstly, can you extract the archive in an external program which you know works? If not, the file is corrupt and your program is probably fine! If it opens okay, continue to investigate...Write a test program which takes the .tar.gz as input and outputs the .tar file (i.e. uses GZIPInputStream only). Then check this .tar using an external reader to see if it's valid. If so, then all is good so far. If not, something isn't working with the Java GZip extraction.Finally test the entire program you have above. If it's still causing a problem, the error must lie in TarInputStream (either in its methods reading from the GZIPInputStream, or decoding functionality).That should help you narrow down where the problem is occurring, and hence focus on where to implement a fix. Also check the docs for TarInputStream to ensure there are no other initialisation methods you're supposed to invoke before calling getNextEntry(). Also check the bug database for your library, and Google for people with similar problems. If you've tried all that and are still stuck, post back.
Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )