summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libjava/ChangeLog14
-rw-r--r--libjava/java/io/File.java56
2 files changed, 56 insertions, 14 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index a7dc8273307..faa0b979b6a 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,17 @@
+2004-09-09 Jeroen Frijters <jeroen@frijters.net>
+
+ (normalizePath): Added special case for windows systems.
+
+2004-09-09 Michael Koch <konqueror@gmx.de>
+
+ * java/io/File.java
+ (dupSeparator): Made private.
+ (File(URI)): New constructor.
+ (getParentFile): Fixed javadoc.
+ (createTempFile): Reformated.
+ (setReadOnly): Added comment.
+ (deleteOnExit): Merged javadoc with classpath version.
+
2004-09-09 Michael Koch <konqueror@gmx.de>
* Makefile.am: Don't try to include deps.mk.
diff --git a/libjava/java/io/File.java b/libjava/java/io/File.java
index 2626d47e9e1..187558dacb4 100644
--- a/libjava/java/io/File.java
+++ b/libjava/java/io/File.java
@@ -57,8 +57,8 @@ import gnu.gcj.runtime.FileDeleter;
* types of path separators ("/" versus "\", for example). It also
* contains method useful for creating and deleting files and directories.
*
- * @author Aaron M. Renn <arenn@urbanophile.com>
- * @author Tom Tromey <tromey@cygnus.com>
+ * @author Aaron M. Renn (arenn@urbanophile.com)
+ * @author Tom Tromey (tromey@cygnus.com)
*/
public class File implements Serializable, Comparable
{
@@ -91,6 +91,7 @@ public class File implements Serializable, Comparable
* An example separator string would be "/" on the GNU system.
*/
public static final String separator = System.getProperty("file.separator");
+ private static final String dupSeparator = separator + separator;
/**
* This is the first character of the file separator string. On many
@@ -118,7 +119,6 @@ public class File implements Serializable, Comparable
static final String tmpdir = System.getProperty("java.io.tmpdir");
static int maxPathLen;
static boolean caseSensitive;
- static String dupSeparator = separator + separator;
static
{
@@ -291,7 +291,15 @@ public class File implements Serializable, Comparable
// On Windows, convert any '/' to '\'. This appears to be the same logic
// that Sun's Win32 Java performs.
if (separatorChar == '\\')
- p = p.replace ('/', '\\');
+ {
+ p = p.replace ('/', '\\');
+ // We have to special case the "\c:" prefix.
+ if (p.length() > 2 && p.charAt(0) == '\\' &&
+ ((p.charAt(1) >= 'a' && p.charAt(1) <= 'z') ||
+ (p.charAt(1) >= 'A' && p.charAt(1) <= 'Z')) &&
+ p.charAt(2) == ':')
+ p = p.substring(1);
+ }
int dupIndex = p.indexOf(dupSeparator);
int plen = p.length();
@@ -413,6 +421,23 @@ public class File implements Serializable, Comparable
}
/**
+ * This method initializes a new <code>File</code> object to represent
+ * a file corresponding to the specified <code>file:</code> protocol URI.
+ *
+ * @param uri The uri.
+ */
+ public File(URI uri)
+ {
+ if (uri == null)
+ throw new NullPointerException("uri is null");
+
+ if (!uri.getScheme().equals("file"))
+ throw new IllegalArgumentException("invalid uri protocol");
+
+ path = normalizePath(uri.getPath());
+ }
+
+ /**
* This method returns the path of this file as an absolute path name.
* If the path name is already absolute, then it is returned. Otherwise
* the value returned is the current directory plus the separatory
@@ -608,7 +633,7 @@ public class File implements Serializable, Comparable
* This method returns a <code>File</code> object representing the parent
* file of this one.
*
- * @param A <code>File</code> for the parent of this object.
+ * @return a <code>File</code> for the parent of this object.
* <code>null</code>
* will be returned if this object does not have a parent.
*
@@ -1038,16 +1063,16 @@ public class File implements Serializable, Comparable
{
String dirname = tmpdir;
if (dirname == null)
- throw new IOException ("Cannot determine system temporary directory");
+ throw new IOException("Cannot determine system temporary directory");
- directory = new File (dirname);
+ directory = new File(dirname);
if (!directory.exists())
- throw new IOException ("System temporary directory "
- + directory.getName() + " does not exist.");
+ throw new IOException("System temporary directory "
+ + directory.getName() + " does not exist.");
if (!directory.isDirectory())
- throw new IOException ("System temporary directory "
- + directory.getName()
- + " is not really a directory.");
+ throw new IOException("System temporary directory "
+ + directory.getName()
+ + " is not really a directory.");
}
// Check if prefix is at least 3 characters long
@@ -1113,6 +1138,7 @@ public class File implements Serializable, Comparable
*/
public boolean setReadOnly()
{
+ // Do a security check before trying to do anything else.
checkWrite();
return performSetReadOnly();
}
@@ -1328,8 +1354,10 @@ public class File implements Serializable, Comparable
}
/**
- * Add this File to the set of files to be deleted upon normal
- * termination.
+ * Calling this method requests that the file represented by this object
+ * be deleted when the virtual machine exits. Note that this request cannot
+ * be cancelled. Also, it will only be carried out if the virtual machine
+ * exits normally.
*
* @exception SecurityException If deleting of the file is not allowed
*