Duplicate :
|
Name: gm110360 Date: 05/08/2002 FULL PRODUCT VERSION : java version "1.4.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92) Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode) FULL OPERATING SYSTEM VERSION : Microsoft Windows 2000 [Version 5.00.2195] A DESCRIPTION OF THE PROBLEM : I am trying to retrieve the byte code of classes that are nested 1,2,...n levels deep inside of nested jar, ear and war files. However, I run into problems when trying to retrieve data from compressed nested jar, ear and war files. The clasfile data gets truncated or entries are not listed. The problem dissappears when I use jar files that are not compressed. I discovered that when I run the following code on a jar that contains compressed entries, I can retrieve the compressed size of all jar entries that are not inside of nested jars. However if a jar entry is nested, I always get –1 as the compression size. JarFile jarFile = new JarFile("myapp.ear"); JarEntry entry1 = jarFile.getJarEntry("myapp.war"); // always correct size compressed/ not compressed int size1 = entry1.getCompressedSize(); JarInputStream(jarFile.getInputStream(entry)) JarEntry entry2 = inputStream.getNextJarEntry(); // always -1 if compressed int size2 = entry2.getCompressedSize(); I figure whether the nested entries are compressed or not, the right size should be returned. Is this a bug in the java API or is there a better way to go about retrieving the byte code of classes that are nested 1,2,...n levels deep inside of nested jar, ear and war files? ~Nathan ###@###.### STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : 1. Run the following code: JarFile jarFile = new JarFile("myapp.ear"); JarEntry entry1 = jarFile.getJarEntry("myapp.war"); // always correct size compressed/ not compressed int size1 = entry1.getCompressedSize(); JarInputStream inputStream = JarInputStream (jarFile.getInputStream(entry)); JarEntry entry2 = inputStream.getNextJarEntry(); // always -1 if compressed int size2 = entry2.getCompressedSize(); 2. Try to write entry2 out to a file. It will always be corrupt and of the wrong size!?! EXPECTED VERSUS ACTUAL BEHAVIOR : I should always get the correct compressed size and valid data when calling jarInputStream.getNextJarEntry() or jarEntry2.getCompressedSize(); However, I never do. ERROR MESSAGES/STACK TRACES THAT OCCUR : JarEntry=org/jdom/adapters/AbstractDOMAdapter.class;compressed size=-1;decom pressed size=-1 closing entry... JarEntry=org/jdom/adapters/CrimsonDOMAdapter.class;compressed size=-1;decomp ressed size=-1 closing entry... JarEntry=org/jdom/adapters/DOMAdapter.class;compressed size=-1;decompressed size=-1 closing entry... JarEntry=org/jdom/adapters/OracleV1DOMAdapter.class;compressed size=-1;decom pressed size=-1 closing entry... JarEntry=org/jdom/adapters/OracleV2DOMAdapter.class;compressed size=-1;decom pressed size=-1 This bug can be reproduced always. ---------- BEGIN SOURCE ---------- JarFile jarFile = new JarFile("myapp.ear"); JarEntry entry1 = jarFile.getJarEntry("myapp.war"); // always correct size compressed/ not compressed int size1 = entry1.getCompressedSize(); JarInputStream inputStream = JarInputStream(jarFile.getInputStream(entry1)); JarEntry entry2 = inputStream.getNextJarEntry("myClass.class"); // always -1 if compressed int size2 = entry2.getCompressedSize(); ---------- END SOURCE ---------- (Review ID: 146284) ======================================================================