Skip to content
Advertisement

Random “Unexpected end of Zlib input stream” exception when trying to gunzip files

I have a class that is supposed to extract a given tar.gz file into a simple .tar file. But for some files this exception is thrown :

java.io.EOFException: Unexpected end of ZLIB input stream

The method managing the extraction look like this :

GZIPInputStream gzipInputStream;
FileOutputStream fileOutputStream;
byte data[] = new byte[BUFFER];
gzipInputStream = new GZIPInputStream( baseInputStream );
fileOutputStream = new FileOutputStream( destinationFile );
while ( ( count = gzipInputStream.read( data, 0, BUFFER ) ) != -1 )
{
    fileOutputStream.write( data, 0, count );
}
fileOutputStream.flush();
fileOutputStream.close();
gzipInputStream.close();

The strange thing is that the exception is thrown for some files and sometimes it does not, but I can’t figure out why… 🙁

Am I missing something ?

Many thanks,

Advertisement

Answer

The error was due to a concurrent access to the file by another thread.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement