[jboss-cvs] JBossAS SVN: r95046 - in projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs: spi and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 16 11:42:45 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-10-16 11:42:45 -0400 (Fri, 16 Oct 2009)
New Revision: 95046

Modified:
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VirtualFile.java
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/RealFileSystem.java
Log:
Add method to VirtualFile to resolve one path against another; use this method to avoid excessive string copying in recursion in RealFileSystem

Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VirtualFile.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VirtualFile.java	2009-10-16 15:32:07 UTC (rev 95045)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VirtualFile.java	2009-10-16 15:42:45 UTC (rev 95046)
@@ -96,6 +96,31 @@
     }
 
     /**
+     * Get the path name relative to a parent virtual file.  If the given virtual file is not a parent of
+     * this virtual file, then an {@code IllegalArgumentException} is thrown.
+     *
+     * @param parent the parent virtual file
+     * @return the relative path name as a string
+     * @throws IllegalArgumentException if the given virtual file is not a parent of this virtual file
+     */
+    public String getPathNameRelativeTo(VirtualFile parent) throws IllegalArgumentException {
+        final StringBuilder builder = new StringBuilder(160);
+        getPathNameRelativeTo(parent, builder);
+        return builder.toString();
+    }
+
+    private void getPathNameRelativeTo(VirtualFile parent, StringBuilder builder) {
+        if (this.parent == null) {
+            throw new IllegalArgumentException("Given parent is not an ancestor of this virtual file");
+        }
+        if (!this.parent.equals(parent)) {
+            this.parent.getPathNameRelativeTo(parent, builder);
+            builder.append('/');
+        }
+        builder.append(name);
+    }
+
+    /**
      * Get the absolute VFS full path name. If this is a URL then directory entries will have a trailing slash.
      *
      * @param url whether or not this path is being used for a URL

Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/RealFileSystem.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/RealFileSystem.java	2009-10-16 15:32:07 UTC (rev 95045)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/RealFileSystem.java	2009-10-16 15:42:45 UTC (rev 95046)
@@ -46,6 +46,8 @@
      */
     public static final RealFileSystem ROOT_INSTANCE = new RealFileSystem(new File(""));
 
+    private static final boolean NEEDS_CONVERSION = File.separatorChar != '/';
+
     private final File realRoot;
 
     /**
@@ -78,8 +80,10 @@
     public File getFile(VirtualFile mountPoint, VirtualFile target) {
         if (mountPoint.equals(target)) {
             return realRoot;
+        } else if (NEEDS_CONVERSION) {
+            return new File(realRoot, target.getPathNameRelativeTo(mountPoint).replace('/', File.separatorChar));
         } else {
-            return new File(getFile(mountPoint, target.getParent()), target.getName());
+            return new File(realRoot, target.getPathNameRelativeTo(mountPoint));
         }
     }
 




More information about the jboss-cvs-commits mailing list