Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

unpacking jar archive

3 views
Skip to first unread message

Stefan Siegl

unread,
Feb 4, 2002, 2:21:33 AM2/4/02
to
I searched for nearly a week in all newsgroups and forums and tested every
bit of code i found there but it isn´t working, so i posted here.

I try to create one final jar archive out of several jar archives. The final
archive should contain all files of all spezified archives (but _not_
compressed)
So I tried it that way:

I create a FileOutputStream fout (this is the final jar archive).

[...]

jout = new JarOutputStream(new FileOutputStream (finalJar);,finalManifest);
// this is the OutputStream for the jar archive !

[...]

Enumeration entries = curJar.entries(); // curJar is the current
jar archive
while (entries.hasMoreElements()) { // for all entries
JarEntry curEntry = (JarEntry) entries.nextElement();
debug("\n now scaning entry "+curEntry.getName());

try


/* this is a method i found in a tips & trick forum - but it isn´t
working :( */
debug("\t not starting with \"META-INF\" ");
// copy header to jout and set compression mode
jout.setMethod(ZipOutputStream.DEFLATED); // compressed
jout.setLevel(8); // compressed
jout.putNextEntry(curEntry);

InputStream currIn = curJar.getInputStream(curEntry);
// InputStream from current entry
BufferedInputStream bis = new BufferedInputStream(currIn);

int sz = (int) curEntry.getSize();
final int N = 1024;
byte buf[] = new byte [N];
int ln = 0;
while (sz > 0 && // should be a workaround for a bug
(ln = bis.read(buf, 0, Math.min(N, sz))) != -1) {
jout.write(buf, 0 , ln);
sz -=ln;
}
currIn.close();
bis.close();

debug ("\t added "+curEntry.getName()+ " to final jar archive");
jout.closeEntry();
debug ("\t closed entry");


/* this is the second tested method and it doesn´t work either :( */

// copy header to jout and set compression mode
jout.setMethod(ZipOutputStream.DEFLATED); // compressed
jout.setLevel(8); // compressed
jout.putNextEntry(curEntry);

InputStream currIn = curJar.getInputStream(curEntry);
debug("\t bytes available on InputStream :" +currIn.available());

int c;
int count = 0;
while ((c=currIn.read()) >= 0) {
count ++;
jout.write(c);
}
currIn.close();
debug("\t read bytes :"+count);

alreadyAdded.add(curEntry.getName());
debug ("\t added "+curEntry.getName()+ " to final jar archive");
jout.closeEntry();
debug ("\t closed entry");*/
}


} catch (ZipException ze) {
System.out.println(curEntry.getName() +" could not be added to final
archive");
ze.printStackTrace();
} catch (IOException io) {
System.out.println(curEntry.getName() +" could not be added to final
archive");
io.printStackTrace();
}


hope you can read my code ;)
ok when executing this code, i get the following exception:
what is weird, is that the first 2 directories and the first 2 files _could_
be added ?!


now scaning entry org/
not starting with "META-INF"
added org/ to final jar archive
closed entry

now scaning entry org/ksoap/
not starting with "META-INF"
added org/ksoap/ to final jar archive
closed entry

now scaning entry org/ksoap/ClassMap.class
not starting with "META-INF"
added org/ksoap/ClassMap.class to final jar archive
closed entry

now scaning entry org/ksoap/SoapObject.class
not starting with "META-INF"
added org/ksoap/SoapObject.class to final jar archive
closed entry

now scaning entry org/ksoap/Soap.class
not starting with "META-INF"
added org/ksoap/Soap.class to final jar archive
org/ksoap/Soap.class could not be added to final archive
java.util.zip.ZipException: invalid entry compressed size (expected 787 but
got
786 bytes)
at
java.util.zip.ZipOutputStream.closeEntry(ZipOutputStream.java:193)
at GenerateData.createFinalJARArchive(GenerateData.java:546)
at GenerateData.run(GenerateData.java:92)
at GenerateData.main(GenerateData.java:71)

now scaning entry org/ksoap/SoapEnvelope.class
not starting with "META-INF"
org/ksoap/SoapEnvelope.class could not be added to final archive
java.util.zip.ZipException: invalid entry compressed size (expected 787 but
got
786 bytes)
at
java.util.zip.ZipOutputStream.closeEntry(ZipOutputStream.java:193)
at
java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:116)
at
java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:90)
at GenerateData.createFinalJARArchive(GenerateData.java:527)
at GenerateData.run(GenerateData.java:92)
at GenerateData.main(GenerateData.java:71)
[...]


Hope you can help me
Thx
Stefan Siegl

0 new messages