JDK: 1.2beta4-K
Locale: all
OS: solaris2.6
When using ZipEntry's InputStream to read more than 8K bytes will return error
bytes. Following is a test program to reproduce it. Please copy rt.jar file to
your runtime directory.
==========================TestZipInputStream.java========================
import java.io.*;
import java.util.zip.*;
public class TestZipInputStream {
public static void main(String args[]) {
getClassFromJar("java/awt/Component.class", "rt.jar");
}
public static void readRemainder(InputStream in, byte[] bytes) throws Exception {
int len = in.available();
if (len > bytes.length) len = bytes.length;
for (int i = 0; i < len; i++) {
bytes[i] = (byte)in.read();
}
}
public static void getClassFromJar(String className, String jarName) {
ZipFile zf;
byte[] bytes1 = null;
byte[] bytes2 = null;
try{
zf = new ZipFile(jarName);
ZipEntry ze;
ze = zf.getEntry(className);
if (ze == null) return;
InputStream istream = zf.getInputStream(ze);
bytes1 = new byte[istream.available()];
bytes2 = new byte[istream.available()];
istream.read(bytes1);
istream.close();
istream = zf.getInputStream(ze);
readRemainder(istream, bytes2);
istream.close();
zf.close();
int count = 0;
for (int i = 0; i < bytes1.length; i ++) {
String tmp1 = "00"+Integer.toHexString(bytes1[i]);
String tmp2 = "00"+Integer.toHexString(bytes2[i]);
if (!tmp1.equals(tmp2)) {
System.out.println("Found a mismatch error: ");
System.out.println(" Position: " + i);
System.out.println(" In bytes1 is " + tmp1);
System.out.println(" In bytes2 is " + tmp2);
count ++;
if (count >= 40) {
break;
}
}
}
} catch(Exception e){}
}
}
===========================================================================
save this file, also copy rt.jar file to your current dir.
javac TestZipInputStream.java
java TestZipInputStream
see the print out message.
jim.hu@prc 1998-07-14
Locale: all
OS: solaris2.6
When using ZipEntry's InputStream to read more than 8K bytes will return error
bytes. Following is a test program to reproduce it. Please copy rt.jar file to
your runtime directory.
==========================TestZipInputStream.java========================
import java.io.*;
import java.util.zip.*;
public class TestZipInputStream {
public static void main(String args[]) {
getClassFromJar("java/awt/Component.class", "rt.jar");
}
public static void readRemainder(InputStream in, byte[] bytes) throws Exception {
int len = in.available();
if (len > bytes.length) len = bytes.length;
for (int i = 0; i < len; i++) {
bytes[i] = (byte)in.read();
}
}
public static void getClassFromJar(String className, String jarName) {
ZipFile zf;
byte[] bytes1 = null;
byte[] bytes2 = null;
try{
zf = new ZipFile(jarName);
ZipEntry ze;
ze = zf.getEntry(className);
if (ze == null) return;
InputStream istream = zf.getInputStream(ze);
bytes1 = new byte[istream.available()];
bytes2 = new byte[istream.available()];
istream.read(bytes1);
istream.close();
istream = zf.getInputStream(ze);
readRemainder(istream, bytes2);
istream.close();
zf.close();
int count = 0;
for (int i = 0; i < bytes1.length; i ++) {
String tmp1 = "00"+Integer.toHexString(bytes1[i]);
String tmp2 = "00"+Integer.toHexString(bytes2[i]);
if (!tmp1.equals(tmp2)) {
System.out.println("Found a mismatch error: ");
System.out.println(" Position: " + i);
System.out.println(" In bytes1 is " + tmp1);
System.out.println(" In bytes2 is " + tmp2);
count ++;
if (count >= 40) {
break;
}
}
}
} catch(Exception e){}
}
}
===========================================================================
save this file, also copy rt.jar file to your current dir.
javac TestZipInputStream.java
java TestZipInputStream
see the print out message.
jim.hu@prc 1998-07-14
- duplicates
-
JDK-4269908 compressed jar files causing zip exception when searching for classes
-
- Closed
-