JDK-4079029 : ZipInputStream isn't propagating info to ZipEntry via getNextEntry
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 1.1.3
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1997-09-15
  • Updated: 1998-01-21
  • Resolved: 1998-01-21
Related Reports
Relates :  
Description

Name: paC48320			Date: 09/15/97


Using a ZipInputStream on a JAR(ZIP) file, the
ZipEntry data retrieved via getNextEntry doesn't
have the CRC, Size or Compressed size fields propagated
properly using DEFLATED mode.  The reason for this is in
examining ZipOutputStream source, the LOCEXT header is being
written at the end of the data, however the ZipInputStream isn't
accessing the information.  Thus, if you're scanning through
a JAR file, the only way to objtain the size, csize and crc
for a ZipEntry is to look at the CEN info, via ZipFile.entries().

This is definitely a bug, You should be able to traverse
a Zip file and get the size info propageted into the ZipEntries
properly.  The following code demonstrates the problem...

// zipbug demonstrates bug in Zip code

import java.util.zip.*;
import java.util.Enumeration;
import java.io.*;

public class zipbug
{
   static File zipFile_ = new File("zipbug.zip");
	static int theSize_ = 0;
	
   static void writeEntries(int count) throws Exception
   {	
		FileOutputStream fo = new FileOutputStream(zipFile_);
		ZipOutputStream out = new ZipOutputStream(fo);
		ZipEntry entry;
		
		String string = new String("This is only a test...");
		byte [] bytes = string.getBytes();
		theSize_ = bytes.length;
		System.out.println("String is " + string + " length = " + theSize_);		
		for(int i = 0;i < count;i++)
		{
           entry = new ZipEntry(new String("Testing " + i));
		    entry.setMethod(ZipEntry.DEFLATED);
			entry.setSize(theSize_);
		
		    out.putNextEntry(entry);
		    out.write(bytes,0,theSize_);
		}
		out.close();
		fo.close();
   }
	
   static void getEntries() throws Exception
   {
	    System.out.println("Scanning via Central Info and ZipFile..\n");
		ZipFile zip = new ZipFile(zipFile_);
		Enumeration entries = zip.entries();
		ZipEntry entry;
		while(entries.hasMoreElements())
		{
		    entry = (ZipEntry)entries.nextElement();
		    System.out.print("Entry Named " + entry.getName() + " Size=" + entry.getSize());
			if(entry.getSize() != theSize_)
			    System.out.println(" [Failed]");
			else
			    System.out.println(" [OK]");
				
		}
		zip.close();
   }
	
   static void scanEntries() throws Exception
   {
		System.out.println("Scanning via LOC Info and ZipInputStream..\n");
		FileInputStream fi = new FileInputStream(zipFile_);
		ZipInputStream in = new ZipInputStream(fi);
		ZipEntry entry;
		while(true)
		{
		    entry = in.getNextEntry();
			if(entry == null)
			    break;
		    System.out.print("Entry Named " + entry.getName() + " Size=" + entry.getSize());
			if(entry.getSize() != theSize_)
			    System.out.println(" [Failed]");
			else
			    System.out.println(" [OK]");
		}
		in.close();
		fi.close();
	}			
		
   static public void main(String args[])
   {
       try
       {
			writeEntries(10);
			getEntries();
			scanEntries();           
       } catch (Exception e)
       {
		    System.out.println(e.toString());
       }
   }
		   	
	
}   

company - Park City Group , email - ###@###.###
======================================================================

Comments
EVALUATION Actually, the information does get passed to the ZipEntry object *after* the entry has been completely read, or nextEntry() has been called to advance to the next entry. This only allows access to the crc, size, and compressed size after the entry data has been read but is a consequence of having to read from an input stream.
11-06-2004

WORK AROUND Name: paC48320 Date: 09/15/97 Forced to Enumerate entries via ZipFile even though we're traversing zip file via ZipInputStream. Not a very good workaround at all. ======================================================================
11-06-2004