How to create a jar having the conents of the jar in byte array?
Posted on 2002-03-28
I have a server and client application. My server returns the contents of the jar in the form of byte array to the client on a particluar method call. Now at the client end, i want to reconstruct the jar to be used. How do I do this?
The server uses the JarInputStream to read the contents of the jar to be returned. I have tried using the JarOutputStream, but looks like this works fine if we have spearate class files to be added to the jar. Now that I have the contents of the jar itself, how do i recreate the jar?
Here is the server code that send the jar contents as bytes
JarFile jar=new JarFile("new.jar") ;
JarEntry jarEntry = jar.getJarEntry(
InputStream jarStream = jar.getInputStream(jarEntry) ;
byte jarContents = new byte[jarStream.available()] ;
//Read the contents into a byte array
int len= jarStream.read(jarContents, 0,
return jarContents ;
At the client end, I tried
File tmp = new File("D:\\Zenith\\ContentMgmt\\FS0\\temp.jar") ;
FileOutputStream out = new FileOutputStream (tmp) ;
JarOutputStream jos = new JarOutputStream(out) ;
ZipEntry zipentry = new ZipEntry(pw.className);
This seems to create a temp.jar, but when i try to view using Winzip, i cannot see any files in it. But with jar tvf temp.jar command at the prompt shows me
"3281 Thu Mar 28 14:15:26 IST 2002 A.class"
I am unable to figure out what is happening.
Can anyone please help me with this?