Name: nt126004 Date: 02/11/2003
FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
FULL OPERATING SYSTEM VERSION : SUSE LINUX 8.0.
ADDITIONAL OPERATING SYSTEMS : Windows 98
A DESCRIPTION OF THE PROBLEM :
When I decompress a Zip file with many directories and check
the checksum, the result is different from the one I have
got when I compress, although the files are well
decompressed. It doesn't happen with all the directories and
It isn't files' fault.
I am using a source code directly downloaded from sun's
website, as it is part of a bigger zip's classes example, so
it't harder to decide if it's a bug or a programmers fault.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Get a large directory and compress it in a zip file. Get
the checksum.
2.Decompress the zip file of the previous step and get the
checksum again.
3.The decompress action is well done but the checksums are
different.
EXPECTED VERSUS ACTUAL BEHAVIOR :
The checksums at compression and decompression should be the
same.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
It doesn't show any error message.
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
// it is very important which arguments you give to the program.
// Try this class and give the parameters I put up the main method. This
// directory is from the Tomcat 4.0. You realize that the checksums are
// different.
/*
* ZipExample.java
*
* Created on 4 de febrero de 2003, 13:36
*/
import java.io.*;
import java.util.zip.*;
/**
*
* @author gonzalo
*/
public class ZipExample {
static final int BUFFER = 2048;
/** Creates a new instance of Class */
public ZipExample() {
}
public long zip (String pathDest,String[] filesToCompress)
{
CheckedOutputStream checksum=null;
//Compress
try {
BufferedInputStream origin = null;
FileOutputStream dest = new
FileOutputStream(pathDest);
checksum = new
CheckedOutputStream(dest, new Adler32());
ZipOutputStream out = new
ZipOutputStream(new
BufferedOutputStream(checksum));
out.setMethod(ZipOutputStream.DEFLATED);
byte data[] = new byte[BUFFER];
// get a list of files from current directory
File f = new File(pathDest);
for (int i=1; i<filesToCompress.length; i++) {
System.out.println("Adding: "+filesToCompress[i]);
FileInputStream fi = new
FileInputStream(filesToCompress[i]);
origin = new
BufferedInputStream(fi, BUFFER);
ZipEntry entry = new ZipEntry(filesToCompress[i]);
out.putNextEntry(entry);
int count;
while((count = origin.read(data, 0,
BUFFER)) != -1) {
out.write(data, 0, count);
}
origin.close();
}
out.close();
} catch(Exception e) {
e.printStackTrace();
}
return checksum.getChecksum().getValue();
}
public long unzip (String zipFilePath){
//Decompress
CheckedInputStream checksum= null;
try {
BufferedOutputStream dest = null;
FileInputStream fis = new FileInputStream(zipFilePath);
checksum = new CheckedInputStream(fis, new Adler32());
ZipInputStream zis = new
ZipInputStream(new
BufferedInputStream(checksum));
ZipEntry entry;
while((entry = zis.getNextEntry()) != null) {
System.out.println("Extracting: " +entry);
int count;
byte data[] = new byte[BUFFER];
// write the files to the disk
FileOutputStream fos = new
FileOutputStream(entry.getName());
dest = new BufferedOutputStream(fos,
BUFFER);
while ((count = zis.read(data, 0,
BUFFER)) != -1) {
dest.write(data, 0, count);
}
dest.flush();
dest.close();
}
zis.close();
} catch(Exception e) {
e.printStackTrace();
}
return checksum.getChecksum().getValue();
}
/* These are the arguments of the main method
* /zipFile1.zip
/ffjuser40ce/tomcat401_base/conf/catalina.policy
/ffjuser40ce/tomcat401_base/conf/server-noexamples.xml.config
/ffjuser40ce/tomcat401_base/conf/tomcat-users.xml
/ffjuser40ce/tomcat401_base/conf/server.xml
/ffjuser40ce/tomcat401_base/conf/web.xml
/ffjuser40ce/tomcat401_base/webapps/ROOT/jakarta-banner.gif
/ffjuser40ce/tomcat401_base/webapps/ROOT/index.html
/ffjuser40ce/tomcat401_base/webapps/ROOT/tomcat.gif
/ffjuser40ce/tomcat401_base/webapps/ROOT/WEB-INF/web.xml
/ffjuser40ce/tomcat401_base/webapps/ROOT/tomcat-power.gif
/ffjuser40ce/tomcat401_base/webapps/manager/WEB-INF/web.xml
/ffjuser40ce/tomcat401_base/webapps/webdav/index.html
/ffjuser40ce/tomcat401_base/webapps/webdav/tomcat.gif
/ffjuser40ce/tomcat401_base/webapps/webdav/WEB-INF/web.xml
/ffjuser40ce/tomcat401_base/webapps/webdav/tomcat-power.gif
*/
public static void main (String argv[]) {
long compressChecksum;
long decompressChecksum;
if (argv.length == 0) {
System.out.println ("\nUse: java ZipExample target_Zip_File fileSource1 fileSource2 ...\n");
System.out.println ("target_Zip_File : Zip file where you want to compress the files");
System.out.println ("fileSource1, fileSource2 ... : Files you want to compress");
} else
{
ZipExample ej = new ZipExample();
compressChecksum = ej.zip (argv[0],argv);
System.out.println("\nCompress checksum: "+compressChecksum+"\n");
decompressChecksum = ej.unzip (argv[0]);
System.out.println("\nDecompress checksum: "+decompressChecksum);
System.out.println("\nChecksum after compress ("+compressChecksum
+") should be equal to the checksum after decompress ("+decompressChecksum+")");
//System.out.println("Checksum after decompress "+decompressChecksum);
}
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
I'm sorry I haven't found a solution yet.
(Review ID: 180617)
======================================================================