1 22 package org.jboss.net.protocol.vfsfile; 23 24 import org.jboss.virtual.VFS; 25 import org.jboss.virtual.VirtualFile; 26 27 import java.io.File ; 28 import java.io.IOException ; 29 import java.io.InputStream ; 30 import java.net.URL ; 31 import java.net.URLConnection ; 32 import java.net.URLStreamHandler ; 33 34 40 public class Handler extends URLStreamHandler 41 { 42 43 protected URLConnection openConnection(URL u) throws IOException 44 { 45 String file = u.toString().substring(8); File fp = new File(file); 47 48 File parent = fp; 49 File curr = fp; 50 String relative = fp.getName(); 51 while ((curr = curr.getParentFile()) != null) 52 { 53 parent = curr; 54 if (parent.getParentFile() != null) relative = parent.getName() + "/" + relative; 55 } 56 57 URL url = parent.toURL(); 58 59 VFS vfs = VFS.getVFS(url); 60 VirtualFile vf = vfs.findChild(relative); 61 62 63 return new VirtualFileURLConnection(url, vf); 64 } 65 66 67 public static void main(String [] args) throws Exception 68 { 69 System.setProperty("java.protocol.handler.pkgs", "org.jboss.net.protocol"); 70 URL url = new URL ("vfsfile:/c:/tmp/parent.jar/foo.jar/urlstream.java"); 73 InputStream is = url.openStream(); 74 while (is.available() != 0) 75 { 76 System.out.print((char)is.read()); 77 } 78 is.close(); 79 80 } 81 } 82 | Popular Tags |