File.java (toURI): Merge from Classpath.
authorAnthony Green <green@redhat.com>
Tue, 6 Jul 2004 02:52:54 +0000 (02:52 +0000)
committerAnthony Green <green@gcc.gnu.org>
Tue, 6 Jul 2004 02:52:54 +0000 (02:52 +0000)
2004-07-05  Anthony Green  <green@redhat.com>
                                                                                                                                               * java/io/File.java (toURI): Merge from Classpath.

From-SVN: r84145

libjava/ChangeLog
libjava/java/io/File.java

index 4cff650aac7e473c9f4534d18cd6cacf14d70674..66f3f41a1d7b1b327831c022e7bb1a646144cdb2 100644 (file)
@@ -1,3 +1,7 @@
+2004-07-05  Anthony Green  <green@redhat.com>
+       
+       * java/io/File.java (toURI): Merge from Classpath.
+
 2004-07-05  Bryce McKinlay  <mckinlay@redhat.com>
 
        * gnu/gcj/runtime/VMClassLoader.java (init): Check classpath entry
index 53ae529c6fe554e33e416eccd4cb8f6392baf146..47f18b533b3d12ec9c5099c80ae999281f7323e0 100644 (file)
@@ -40,6 +40,8 @@ exception statement from your version. */
 package java.io;
 
 import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import gnu.classpath.Configuration;
 import gnu.gcj.runtime.FileDeleter;
@@ -874,6 +876,28 @@ public class File implements Serializable, Comparable
     return path;
   }
 
+  /**
+   * @return A <code>URI</code> for this object.
+   */
+  public URI toURI()
+  {
+    String abspath = getAbsolutePath();
+
+    if (isDirectory())
+      abspath = abspath + separator;
+        
+    try
+      {
+       return new URI("file", "", abspath.replace(separatorChar, '/'));
+      }
+    catch (URISyntaxException use)
+      {
+        // Can't happen.
+        throw (InternalError) new InternalError("Unconvertible file: "
+                                               + this).initCause(use);
+      }
+  }
+
   /**
    * This method returns a <code>URL</code> with the <code>file:</code>
    * protocol that represents this file.  The exact form of this URL is