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!

error with GZIP unzip Java 6 64bit 1.6.0_10_b33 Linux

807588Feb 6 2009
Hi,
I wrote an app that, among other things compresses selected files with GZIPOutputStream. This works, not only on 64bit Linux but 32 bit Windows. The file is compressed with my code and decompressed with gunzip. Here is that code snippet.
				try {
					int read;
					boolean deleted = false;
					fis = new FileInputStream(file);
					bis = new BufferedInputStream(fis);
					File tmp = new File(file.getAbsolutePath() + ".gz");
					if (tmp.exists()) {
						tmp.delete();
					}
					fos = new FileOutputStream(tmp);
					gos = new GZIPOutputStream(fos);
					if (gos == null) {
						logger.log(Level.WARNING, "GZip outout file not created, bypassing compression");
					}
					/*
					 * compress file and delete original if compress successful
					 */
					
					byte[] buffer = new byte[MaxSize];
					
					while ((read = bis.read(buffer)) > 0) {
						gos.write(buffer, 0, read);
					}
					gos.finish();  // was added to see if that was an issue as some google hit suggested
					bis.close();
					gos.close();
					bis = null;
					gos = null;
I next added a recover method to decompress with GZIPInputStream. Here is that code.
		FileInputStream fis = null;
		GZIPInputStream gis = null;
		FileOutputStream fos = null;
		BufferedOutputStream bos = null;
		byte buffer[] = new byte[MaxSize];
		int read = 0;
		if (!fileStr.endsWith(".gz")) {			
			throw new InvalidFileException("gz");
		}
		
		try {
			file = new File(fileStr);
			if (!file.canRead()) {
				throw new IOException("Cant read file " + fileStr);
			}
			fis = new FileInputStream(file);
			gis = new GZIPInputStream(fis);
			int index = fileStr.indexOf(".gz");
			

			if (index != -1) {
				String tmp = fileStr.substring(0, index);
				fos = new FileOutputStream(tmp);
				bos = new BufferedOutputStream(fos);
			}

			while ((read = gis.read(buffer, 0, MaxSize)) > 0) {
				bos.write(buffer, 0, read);
			}
			gis.close();
			bos.close();
			gis = null;
			bos = null;
The error I am seeing is Unexpected end of ZLIB input stream.

I have tried this on both xxx.txt.gz files I created and files created by gzip utility. I had also tried read(bufffer) without the offset and length.

So if anyone sees anything I am missing or knows of an existing bug in the implementation of the deflate logic in the 64 bit Java 6 Sun compiler I would appreciate your input.

Thanks,

Walt Corey
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 6 2009
Added on Feb 6 2009
0 comments
517 views