From: Anthony Green Date: Tue, 6 Jul 2004 02:52:54 +0000 (+0000) Subject: File.java (toURI): Merge from Classpath. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=23f99379d3d3d445c15f7a3c2e29e44c06afb255;p=gcc.git File.java (toURI): Merge from Classpath. 2004-07-05 Anthony Green * java/io/File.java (toURI): Merge from Classpath. From-SVN: r84145 --- diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 4cff650aac7..66f3f41a1d7 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,7 @@ +2004-07-05 Anthony Green + + * java/io/File.java (toURI): Merge from Classpath. + 2004-07-05 Bryce McKinlay * gnu/gcj/runtime/VMClassLoader.java (init): Check classpath entry diff --git a/libjava/java/io/File.java b/libjava/java/io/File.java index 53ae529c6fe..47f18b533b3 100644 --- a/libjava/java/io/File.java +++ b/libjava/java/io/File.java @@ -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 URI 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 URL with the file: * protocol that represents this file. The exact form of this URL is