[jboss-cvs] JBossAS SVN: r101783 - projects/vfs/trunk/src/main/java/org/jboss/vfs.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 3 11:48:39 EST 2010


Author: david.lloyd at jboss.com
Date: 2010-03-03 11:48:39 -0500 (Wed, 03 Mar 2010)
New Revision: 101783

Modified:
   projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java
   projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java
Log:
Add as(File|Directory)UR(I|L), slap some warnings on the stuff I dont like :)

Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java	2010-03-03 16:33:03 UTC (rev 101782)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java	2010-03-03 16:48:39 UTC (rev 101783)
@@ -482,12 +482,18 @@
      * Get the virtual URL for a virtual file.  This URL can be used to access the virtual file; however, taking the file
      * part of the URL and attempting to use it with the {@link java.io.File} class may fail if the file is not present
      * on the physical filesystem, and in general should not be attempted.
+     * <b>Note:</b> if the given VirtualFile refers to a directory <b>at the time of this
+     * method invocation</b>, a trailing slash will be appended to the URL; this means that invoking
+     * this method may require a filesystem access, and in addition, may not produce consistent results
+     * over time.
      *
      * @param file the virtual file
      *
      * @return the URL
      *
      * @throws MalformedURLException if the file cannot be coerced into a URL for some reason
+     * @see VirtualFile#asDirectoryURL()
+     * @see VirtualFile#asFileURL()
      */
     public static URL getVirtualURL(VirtualFile file) throws MalformedURLException {
         // todo: specify the URL handler directly as a minor optimization
@@ -496,12 +502,18 @@
 
     /**
      * Get the virtual URI for a virtual file.
+     * <b>Note:</b> if the given VirtualFile refers to a directory <b>at the time of this
+     * method invocation</b>, a trailing slash will be appended to the URI; this means that invoking
+     * this method may require a filesystem access, and in addition, may not produce consistent results
+     * over time.
      *
      * @param file the virtual file
      *
      * @return the URI
      *
      * @throws URISyntaxException if the file cannot be coerced into a URI for some reason
+     * @see VirtualFile#asDirectoryURI()
+     * @see VirtualFile#asFileURI()
      */
     public static URI getVirtualURI(VirtualFile file) throws URISyntaxException {
         return new URI("file", "", file.getPathName(true), null);

Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java	2010-03-03 16:33:03 UTC (rev 101782)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java	2010-03-03 16:48:39 UTC (rev 101783)
@@ -425,27 +425,85 @@
     }
 
     /**
-     * Get file's URL.
+     * Get file's current URL.  <b>Note:</b> if this VirtualFile refers to a directory <b>at the time of this
+     * method invocation</b>, a trailing slash will be appended to the URL; this means that invoking
+     * this method may require a filesystem access, and in addition, may not produce consistent results
+     * over time.
      *
-     * @return the url
+     * @return the current url
      *
      * @throws MalformedURLException if the URL is somehow malformed
+     * @see VirtualFile#asDirectoryURL()
+     * @see VirtualFile#asFileURL()
      */
     public URL toURL() throws MalformedURLException {
         return VFSUtils.getVirtualURL(this);
     }
 
     /**
-     * Get file's URI.
+     * Get file's current URI.  <b>Note:</b> if this VirtualFile refers to a directory <b>at the time of this
+     * method invocation</b>, a trailing slash will be appended to the URI; this means that invoking
+     * this method may require a filesystem access, and in addition, may not produce consistent results
+     * over time.
      *
-     * @return the uri
+     * @return the current uri
      *
-     * @throws URISyntaxException for any error
+     * @throws URISyntaxException if the URI is somehow malformed
+     * @see VirtualFile#asDirectoryURI()
+     * @see VirtualFile#asFileURI()
      */
     public URI toURI() throws URISyntaxException {
         return VFSUtils.getVirtualURI(this);
     }
     
+   /**
+    * Get file's URL as a directory.  There will always be a trailing {@code "/"} character.
+    *
+    * @return the url
+    *
+    * @throws MalformedURLException if the URL is somehow malformed
+    */
+    public URL asDirectoryURL() throws MalformedURLException {
+       final String pathName = getPathName(false);
+       return new URL("file", "", -1, parent == null ? pathName : pathName + "/");
+    }
+
+   /**
+    * Get file's URI as a directory.  There will always be a trailing {@code "/"} character.
+    *
+    * @return the uri
+    *
+    * @throws URISyntaxException if the URI is somehow malformed
+    */
+    public URI asDirectoryURI() throws URISyntaxException {
+       final String pathName = getPathName(false);
+       return new URI("file", "", parent == null ? pathName : pathName + "/", null);
+    }
+
+   /**
+    * Get file's URL as a file.  There will be no trailing {@code "/"} character unless this {@code VirtualFile}
+    * represents a root.
+    *
+    * @return the url
+    *
+    * @throws MalformedURLException if the URL is somehow malformed
+    */
+    public URL asFileURL() throws MalformedURLException {
+       return new URL("file", "", -1, getPathName(false));
+    }
+
+   /**
+    * Get file's URI as a file.  There will be no trailing {@code "/"} character unless this {@code VirtualFile}
+    * represents a root.
+    *
+    * @return the url
+    *
+    * @throws URISyntaxException if the URI is somehow malformed
+    */
+    public URI asFileURI() throws URISyntaxException {
+       return new URI("file", "", getPathName(false), null);
+    }
+
     /**
      * Get the {@link CodeSigner}s for a the virtual file.
      *




More information about the jboss-cvs-commits mailing list