[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: toURI
From: |
Mark Wielaard |
Subject: |
Re: toURI |
Date: |
Fri, 30 Apr 2004 22:19:40 +0200 |
Hi all,
Tom and I had a little discussion off-list about his File.toURI() patch.
On Fri, 2004-04-30 at 21:29, Tom Tromey wrote:
> Mark> Then I saw toURL() does the same.
> Mark> So I made the attached patch. It doesn't change any mauve results.
> Mark> What do you think?
>
> Looks good to me.
>
> Mark> + throw (InternalError) new InternalError("Uncovertable file: "
>
> Typo, "Unconvertible" -- missing 'n' and s/a/i/
Argh. English language...
I'll commit as follows:
2004-04-30 Tom Tromey <address@hidden>
Mark Wielaard <address@hidden>
* java/io/File.java (toURI): New method.
(toURL): Use isDirectory() directly.
Cheers,
Mark
Index: java/io/File.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/File.java,v
retrieving revision 1.43
diff -u -r1.43 File.java
--- java/io/File.java 26 Apr 2004 20:51:31 -0000 1.43
+++ java/io/File.java 30 Apr 2004 20:18:56 -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.java.io.PlatformHelper;
@@ -766,6 +768,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.
@@ -778,14 +802,10 @@
public URL toURL() throws MalformedURLException
{
String abspath = getAbsolutePath();
-
- try
- {
- if (new File(abspath).isDirectory())
- abspath = abspath + separator;
- }
- catch(Exception _) { }
-
+
+ if (isDirectory())
+ abspath = abspath + separator;
+
return new URL("file", "", abspath.replace(separatorChar, '/'));
}
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: toURI,
Mark Wielaard <=