[jboss-dev-forums] [Design the new POJO MicroContainer] - Another problem with jar urls
scott.stark@jboss.org
do-not-reply at jboss.com
Sat Nov 11 15:07:21 EST 2006
Another example of why we need to drop jar urls is that one cannot obtain an InputStream from which to copy the jar:
| public void testJarURLCopy()
| throws Exception
| {
| FileOutputStream fos = new FileOutputStream("/tmp/x.jar");
| JarOutputStream jos = new JarOutputStream(fos);
| JarEntry je = new JarEntry("META-INF/MANIFEST.MF");
| jos.putNextEntry(je);
| jos.write("Manifest-Version: 1.0\r\n".getBytes());
| jos.write("\r\n".getBytes());
| jos.close();
|
| FileInputStream fis = new FileInputStream("/tmp/x.jar");
| byte[] buffer = new byte[128];
| int read;
| int count = 0;
| while( (read = fis.read(buffer)) > 0 )
| {
| count += read;
| }
| fis.close();
| System.out.println("Read "+count+" bytes from x.jar");
|
| URL jarURL = new URL("jar:file:/tmp/x.jar!/");
| InputStream is = jarURL.openStream();
| int count2 = 0;
| while( (read = is.read(buffer)) > 0 )
| {
| count2 += read;
| }
| is.close();
| System.out.println("Read "+count+" bytes from x.jar");
| assert count == count2 : "expected count == count2";
| }
|
Running this produces:
| [starksm at succubus x]$ java tstjar
| Read 189 bytes from x.jar
| Exception in thread "main" java.io.IOException: no entry name specified
| at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:129)
| at java.net.URL.openStream(URL.java:1007)
| at tstjar.main(tstjar.java:31)
|
To work around this in the vfs level the openStream implementation of a jar needs to detect if it refers to the jar itself and unwrap the jar url to obtain a usable url connection.
We do need to move to custom vfs urls and handlers to have consistent behvior.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3985164#3985164
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3985164
More information about the jboss-dev-forums
mailing list