This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: java.io.File - URI stuff
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Thu, 18 Dec 2003 17:59:40 +0100
- Subject: Patch: java.io.File - URI stuff
Hi list,
I wrote a little patch to add two missing methods to java.io.File to support
URIs. This patch compiles already but cant work as java.net.URI is not
functional yet because of missing java.util.regex which lacks ....
Please review and comment. Okay for commit ?
Michael
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2456
diff -u -b -B -r1.2456 ChangeLog
--- ChangeLog 18 Dec 2003 16:48:32 -0000 1.2456
+++ ChangeLog 18 Dec 2003 16:53:50 -0000
@@ -1,5 +1,11 @@
2003-12-18 Michael Koch <konqueror@gmx.de>
+ * java/io/File.java
+ (File): New constructor.
+ (toURI): New method.
+
+2003-12-18 Michael Koch <konqueror@gmx.de>
+
* java/util/prefs/AbstractPreferences.java
(cachedChildren): New method.
Index: java/io/File.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/File.java,v
retrieving revision 1.37
diff -u -b -B -r1.37 File.java
--- java/io/File.java 22 Oct 2003 08:47:12 -0000 1.37
+++ java/io/File.java 18 Dec 2003 16:53:50 -0000
@@ -39,6 +39,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;
@@ -282,6 +284,30 @@
path = normalizePath (name);
}
+ /**
+ * This method initializes a new <code>File</code> object to represent
+ * a file with the specified uri.
+ *
+ * @param uri The uri of the file
+ *
+ * @exception NullPointerException If uri is null
+ * @exception IllegalArgumentException If the preconditions for uri do not hold
+ *
+ * @since 1.4
+ */
+ public File(URI uri)
+ {
+ if (!uri.isAbsolute()
+ || !uri.getScheme().equals("file")
+ || uri.getPath() == null
+ || uri.getAuthority() != null
+ || uri.getQuery() != null
+ || uri.getFragment() != null)
+ throw new IllegalArgumentException();
+
+ path = normalizePath(uri.getPath());
+ }
+
// Remove duplicate and redundant separator characters.
private String normalizePath(String p)
{
@@ -893,6 +919,26 @@
else
return new URL ("file:" + getAbsolutePath()
+ (isDirectory() ? "/" : ""));
+ }
+
+ /**
+ * This method returns a <code>URI</code> with the <code>file:</code>
+ * protocol that represents this file. The exact form of this URL is
+ * system dependent.
+ *
+ * @return A <code>URI</code> for this object.
+ */
+ public URI toURI()
+ {
+ try
+ {
+ return new URI("file", null, getAbsolutePath(), null);
+ }
+ catch (URISyntaxException e)
+ {
+ // This cannot happen.
+ throw new InternalError("Error during creating URI");
+ }
}
/*