[jboss-cvs] JBossAS SVN: r57765 - in projects/microcontainer/trunk/container/src/main/org/jboss: . net net/protocol net/protocol/vfsfile

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 20 18:15:05 EDT 2006


Author: bill.burke at jboss.com
Date: 2006-10-20 18:15:05 -0400 (Fri, 20 Oct 2006)
New Revision: 57765

Added:
   projects/microcontainer/trunk/container/src/main/org/jboss/net/
   projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/
   projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/
   projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/Handler.java
   projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/VirtualFileURLConnection.java
Log:
URL handler for vfsfile

Added: projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/Handler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/Handler.java	2006-10-20 21:14:12 UTC (rev 57764)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/Handler.java	2006-10-20 22:15:05 UTC (rev 57765)
@@ -0,0 +1,81 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.net.protocol.vfsfile;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+/**
+ * URLStreamHandler for VFS
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class Handler extends URLStreamHandler
+{
+
+   protected URLConnection openConnection(URL u) throws IOException
+   {
+      String file = u.toString().substring(8); // strip out vfsfile:
+      File fp = new File(file);
+
+      File parent = fp;
+      File curr = fp;
+      String relative = fp.getName();
+      while ((curr = curr.getParentFile()) != null)
+      {
+         parent = curr;
+         if (parent.getParentFile() != null) relative = parent.getName() + "/" + relative;
+      }
+
+      URL url = parent.toURL();
+
+      VFS vfs = VFS.getVFS(url);
+      VirtualFile vf = vfs.findChild(relative);
+
+
+      return new VirtualFileURLConnection(url, vf);
+   }
+
+
+   public static void main(String[] args) throws Exception
+   {
+      System.setProperty("java.protocol.handler.pkgs", "org.jboss.net.protocol");
+      //URL url = new URL("vfsfile:/c:/tmp/urlstream.java");
+      //URL url = new URL("vfsfile:/C:\\jboss\\jboss-head\\build\\output\\jboss-5.0.0.Beta\\server\\default\\lib\\jboss.jar\\schema\\xml.xsd");
+      URL url = new URL("vfsfile:/c:/tmp/parent.jar/foo.jar/urlstream.java");
+      InputStream is = url.openStream();
+      while (is.available() != 0)
+      {
+         System.out.print((char)is.read());
+      }
+      is.close();
+
+   }
+}

Added: projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/VirtualFileURLConnection.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/VirtualFileURLConnection.java	2006-10-20 21:14:12 UTC (rev 57764)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/VirtualFileURLConnection.java	2006-10-20 22:15:05 UTC (rev 57765)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.net.protocol.vfsfile;
+
+import org.jboss.virtual.VirtualFile;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+/**
+ * Implements basic URLConnection for a VirtualFile
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class VirtualFileURLConnection extends URLConnection
+{
+   protected VirtualFile file;
+
+   public VirtualFileURLConnection(URL url, VirtualFile file)
+   {
+      super(url);
+      this.file = file;
+   }
+
+   public void connect() throws IOException
+   {
+   }
+
+   public VirtualFile getVirtualFile()
+   {
+      return file;
+   }
+
+
+   public InputStream getInputStream() throws IOException
+   {
+      return file.openStream();
+   }
+}




More information about the jboss-cvs-commits mailing list