Patch: merge File.toURI() from Classpath
Anthony Green
green@redhat.com
Tue Jul 6 02:53:00 GMT 2004
FYI, I'm committing this bit of code from GNU Classpath.
AG
--
Anthony Green <green@redhat.com>
Red Hat, Inc.
-------------- next part --------------
2004-07-05 Anthony Green <green@redhat.com>
* java/io/File.java (toURI): Merge from Classpath.
Index: File.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/File.java,v
retrieving revision 1.38
diff -u -r1.38 File.java
--- File.java 20 Apr 2004 11:37:41 -0000 1.38
+++ File.java 6 Jul 2004 02:47:20 -0000
@@ -40,6 +40,8 @@
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;
@@ -875,6 +877,28 @@
}
/**
+ * @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
* system dependent.
More information about the Java-patches
mailing list