| Relates :   | |
| Relates :   | |
| Relates :   | |
| Relates :   | |
| Relates :   | 
OPERATING SYSTEM(S):
All
FULL JDK VERSION(S):
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b06)
Java HotSpot(TM) Client VM (build 1.6.0_02-b06, mixed mode)
DESCRIPTION:
When JDK 6 is used for unzipping a zip file > 2GB in size, the following exception is thrown:
java.util.zip.ZipException: error in opening zip file
  at java.util.zip.ZipFile.open(Native Method)
  at java.util.zip.ZipFile.<init>(ZipFile.java:114)
  at java.util.zip.ZipFile.<init>(ZipFile.java:75)
  at UnZip.main(UnZip.java:65)
Exact steps to reproduce
  1. Create a zip file > 2GB in size.
  2. Write a simple java program to unzip the file using a Java program
The following testcase was obtained from another sun bug:
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class unzip
{
    public static final void copyInputStream (InputStream in,OutputStream out) throws IOException
    {
        byte[] buffer = new byte [1024];
        int    len;
        while ((len = in.read(buffer)) >= 0)
            out.write(buffer, 0, len);
        in.close();
        out.close();
    }
    public static final void main (String[] args)
    {
        Enumeration entries;
        ZipFile     zipFile=null;
        if (args.length != 1){
            System.err.println("Usage: Unzip zipfile");
            return;
        }
        try{
        	zipFile = new ZipFile(args[0]);
	}catch(IOException ioe){System.out.println("error opening the zipfile");ioe.printStackTrace();}
        	ZipEntry entry=null;
        	entries = zipFile.entries();
        	while (entries.hasMoreElements()){
                System.out.println("Constructing ZipFile...");
                entry = ( ZipEntry ) entries.nextElement();
        	}
        	if (entry.isDirectory()){
        		// Assume directories are stored parents first then children
        		System.err.println("Extracting directory: " + entry.getName());
        		// This is not robust, just for demonstration purposes.
        		(new File(entry.getName())).mkdir();
        		//continue;
        	}
        	System.err.println("Extracting file: " + entry.getName());
		try{
	        	copyInputStream(zipFile.getInputStream(entry),new BufferedOutputStream(new FileOutputStream(entry.getName())));
        		System.out.print("Check memory usage and press 'Enter'...");
	        	System.in.read();
        		zipFile.close();
        	}catch(IOException ioe){ioe.printStackTrace();}
    
    }
}
| 
 |