Hey guys,
Could someone please help me? I am trying to write a Java program that would detect corrupt gzip files. By corrupt I mean those that can't be decompressed with gunzip. I though I would use GZIPInputStream, but the problem is that it reads most of these files without raising an exception... My code is below. Is there any way to achieve my goal?
byte [] buffer = new byte[10];
try
{
GZIPInputStream gzipInputStream =
new GZIPInputStream(new FileInputStream(filename));
int transferred = gzipInputStream.read(buffer); // should be 10
if(transferred == -1)
{
System.out.println("Error. The end of the compressed stream is reached.");
// System.out.println("Time: "+(System.currentTimeMillis() - time1));
return false;
}
else if(transferred != 10)
{
System.out.println("Error. Less than 10 bytes were read.");
return false;
}
}
catch (IOException ioe)
{
System.out.println("Unable to open a file: "+filename);
System.out.println(ioe.getMessage());
// System.out.println("Time: "+(System.currentTimeMillis() - time1));
return false;
}