Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java and corrupt gzip files

807603Oct 29 2007 — edited Oct 29 2007
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;
		}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 26 2007
Added on Oct 29 2007
1 comment
632 views