-
Bug
-
Resolution: Not an Issue
-
P3
-
6
-
None
-
generic
-
solaris_10
When java.util.zip is used to read archives that were generated by third-party implementations (InfoZip in this case), it won't write out exactly what it read. Here is a test case:
$ ./runtest
+ typeset JAVA=/usr/jdk/latest/bin/java
+ typeset JAVAC=/usr/jdk/latest/bin/javac
+ /usr/jdk/latest/bin/java -fullversion
java full version "1.6.0-beta2-b75"
+ zip -v
Copyright (C) 1990-1999 Info-ZIP
Type 'zip "-L"' for software license.
This is Zip 2.3 (November 29th 1999), by Info-ZIP.
Currently maintained by Onno van der Linden. Please send bug reports to
the authors at ###@###.###; see README for details.
Latest sources and executables are at ftp://ftp.cdrom.com/pub/infozip, as of
above date; see http://www.cdrom.com/pub/infozip/Zip.html for other sites.
Compiled with cc for Unix (Sun Sparc/Solaris) on Apr 25 2006.
Zip special compilation options:
USE_EF_UT_TIME
Zip environment options:
ZIP: [none]
ZIPOPT: [none]
+ rm -rf a A.jar
+ mkdir a
+ zip -r A.jar a
adding: a/ (stored 0%)
+ rm -rf a
+ cat CopyZipV1.java
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class CopyZipV1 {
public static void main(String[] args) {
try {
ZipFile zf = new ZipFile(args[0]);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(args[1]));
for (Enumeration entries = zf.entries(); entries.hasMoreElements();) {
ZipEntry ze = (ZipEntry) entries.nextElement();
out.putNextEntry(ze);
InputStream is = zf.getInputStream(ze);
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
is.close();
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
+ /usr/jdk/latest/bin/javac CopyZipV1.java
+ /usr/jdk/latest/bin/java CopyZipV1 A.jar B.jar
+ cat CopyZipV2.java
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class CopyZipV2 {
public static void main(String[] args) {
try {
ZipInputStream in = new ZipInputStream(new FileInputStream(args[0]));
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(args[1]));
ZipEntry ze;
while ((ze = in.getNextEntry()) != null) {
out.putNextEntry(ze);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
in.closeEntry();
}
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
+ /usr/jdk/latest/bin/javac CopyZipV2.java
+ /usr/jdk/latest/bin/java CopyZipV2 A.jar C.jar
+ ls -l A.jar B.jar C.jar
-rw-r--r-- 1 hallo staff 136 May 19 11:46 A.jar
-rw-r--r-- 1 hallo staff 128 May 19 11:46 B.jar
-rw-r--r-- 1 hallo staff 144 May 19 11:46 C.jar
In all cases the archive contains a single directory entry. A.jar was created by zip. B.jar was created by copying A.jar using the ZipFile + ZipOutputStream technique. C.jar was created by copying A.jar using ZipInputStream + ZipOutputStream technique. The copies are different sizes from the original. In fact, the copies themselves are different sizes which is not expected. The ZIP spec probably allows this but I would expect copies to be the same size.
$ ./runtest
+ typeset JAVA=/usr/jdk/latest/bin/java
+ typeset JAVAC=/usr/jdk/latest/bin/javac
+ /usr/jdk/latest/bin/java -fullversion
java full version "1.6.0-beta2-b75"
+ zip -v
Copyright (C) 1990-1999 Info-ZIP
Type 'zip "-L"' for software license.
This is Zip 2.3 (November 29th 1999), by Info-ZIP.
Currently maintained by Onno van der Linden. Please send bug reports to
the authors at ###@###.###; see README for details.
Latest sources and executables are at ftp://ftp.cdrom.com/pub/infozip, as of
above date; see http://www.cdrom.com/pub/infozip/Zip.html for other sites.
Compiled with cc for Unix (Sun Sparc/Solaris) on Apr 25 2006.
Zip special compilation options:
USE_EF_UT_TIME
Zip environment options:
ZIP: [none]
ZIPOPT: [none]
+ rm -rf a A.jar
+ mkdir a
+ zip -r A.jar a
adding: a/ (stored 0%)
+ rm -rf a
+ cat CopyZipV1.java
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class CopyZipV1 {
public static void main(String[] args) {
try {
ZipFile zf = new ZipFile(args[0]);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(args[1]));
for (Enumeration entries = zf.entries(); entries.hasMoreElements();) {
ZipEntry ze = (ZipEntry) entries.nextElement();
out.putNextEntry(ze);
InputStream is = zf.getInputStream(ze);
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
is.close();
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
+ /usr/jdk/latest/bin/javac CopyZipV1.java
+ /usr/jdk/latest/bin/java CopyZipV1 A.jar B.jar
+ cat CopyZipV2.java
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class CopyZipV2 {
public static void main(String[] args) {
try {
ZipInputStream in = new ZipInputStream(new FileInputStream(args[0]));
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(args[1]));
ZipEntry ze;
while ((ze = in.getNextEntry()) != null) {
out.putNextEntry(ze);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
in.closeEntry();
}
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
+ /usr/jdk/latest/bin/javac CopyZipV2.java
+ /usr/jdk/latest/bin/java CopyZipV2 A.jar C.jar
+ ls -l A.jar B.jar C.jar
-rw-r--r-- 1 hallo staff 136 May 19 11:46 A.jar
-rw-r--r-- 1 hallo staff 128 May 19 11:46 B.jar
-rw-r--r-- 1 hallo staff 144 May 19 11:46 C.jar
In all cases the archive contains a single directory entry. A.jar was created by zip. B.jar was created by copying A.jar using the ZipFile + ZipOutputStream technique. C.jar was created by copying A.jar using ZipInputStream + ZipOutputStream technique. The copies are different sizes from the original. In fact, the copies themselves are different sizes which is not expected. The ZIP spec probably allows this but I would expect copies to be the same size.