Index: java/io/File.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/File.java,v
retrieving revision 1.38
diff -u -b -B -r1.38 File.java
--- java/io/File.java 15 Jan 2004 21:11:30 -0000 1.38
+++ java/io/File.java 3 Mar 2004 21:15:55 -0000
@@ -1,5 +1,6 @@
/* File.java -- Class representing a file on disk
- Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -91,15 +92,17 @@
*/
public static final char pathSeparatorChar = pathSeparator.charAt(0);
- // FIXME: We support only caseSensitive filesystems currently.
- static boolean caseSensitive = true;
+ static boolean caseSensitive;
static
{
if (Configuration.INIT_LOAD_LIBRARY)
{
- System.loadLibrary ("javaio");
+ System.loadLibrary("javaio");
}
+
+ // FIXME: We support only caseSensitive filesystems currently.
+ caseSensitive = true;
}
/**
@@ -151,7 +154,7 @@
if (!exists())
return false;
- return canReadInternal (path);
+ return canReadInternal(path);
}
/**
@@ -179,7 +182,7 @@
return false;
if (!isDirectory())
- return canWriteInternal (path);
+ return canWriteInternal(path);
else
try
{
@@ -190,7 +193,7 @@
will fail.
*/
String filename = (separatorChar!='\\')?"test-dir-write":"tst";
- File test = createTempFile (filename, null, this);
+ File test = createTempFile(filename, null, this);
return (test != null && test.delete());
}
catch (IOException ioe)
@@ -219,7 +222,7 @@
public boolean createNewFile() throws IOException
{
checkWrite();
- return createInternal (path);
+ return createInternal(path);
}
/*
@@ -241,7 +244,7 @@
SecurityManager s = System.getSecurityManager();
if (s != null)
- s.checkDelete (path);
+ s.checkDelete(path);
return deleteInternal(path);
}
@@ -261,7 +264,7 @@
* @return true
if the two objects are equal,
* false
otherwise.
*/
- public boolean equals (Object obj)
+ public boolean equals(Object obj)
{
if (! (obj instanceof File))
return false;
@@ -269,9 +272,9 @@
File other = (File) obj;
if (caseSensitive)
- return path.equals (other.path);
+ return path.equals(other.path);
else
- return path.equalsIgnoreCase (other.path);
+ return path.equalsIgnoreCase(other.path);
}
/*
@@ -290,7 +293,7 @@
public boolean exists()
{
checkRead();
- return existsInternal (path);
+ return existsInternal(path);
}
/**
@@ -299,7 +302,7 @@
*
* @param name The path name of the file
*/
- public File (String name)
+ public File(String name)
{
path = name;
@@ -322,9 +325,9 @@
* @param dirPath The path to the directory the file resides in
* @param name The name of the file
*/
- public File (String dirPath, String name)
+ public File(String dirPath, String name)
{
- this (dirPath == null ? (File) null : new File (dirPath), name);
+ this (dirPath == null ? (File) null : new File(dirPath), name);
}
/**
@@ -337,7 +340,7 @@
* @param directory The directory this file resides in
* @param name The name of the file
*/
- public File (File directory, String name)
+ public File(File directory, String name)
{
if (directory == null)
{
@@ -370,11 +373,11 @@
if (isAbsolute())
return path;
- String dir = System.getProperty ("user.dir");
+ String dir = System.getProperty("user.dir");
if (dir == null)
return path;
- if (PlatformHelper.endWithSeparator (dir))
+ if (PlatformHelper.endWithSeparator(dir))
return dir + path;
return dir + separator + path;
@@ -390,7 +393,7 @@
*/
public File getAbsoluteFile()
{
- return new File (getAbsolutePath());
+ return new File(getAbsolutePath());
}
/**
@@ -425,7 +428,7 @@
*/
public File getCanonicalFile() throws IOException
{
- return new File (getCanonicalPath());
+ return new File(getCanonicalPath());
}
/**
@@ -437,14 +440,14 @@
*/
public String getName()
{
- int pos = PlatformHelper.lastIndexOfSeparator (path);
+ int pos = PlatformHelper.lastIndexOfSeparator(path);
if (pos == -1)
return path;
- if (PlatformHelper.endWithSeparator (path))
+ if (PlatformHelper.endWithSeparator(path))
return "";
- return path.substring (pos + separator.length());
+ return path.substring(pos + separator.length());
}
/**
@@ -456,16 +459,16 @@
*/
public String getParent()
{
- if (PlatformHelper.isRootDirectory (path))
+ if (PlatformHelper.isRootDirectory(path))
return null;
String par_path = path;
- int pos = PlatformHelper.lastIndexOfSeparator (par_path);
+ int pos = PlatformHelper.lastIndexOfSeparator(par_path);
if (pos == -1)
return null;
- return par_path.substring (0, pos);
+ return par_path.substring(0, pos);
}
/**
@@ -481,7 +484,7 @@
public File getParentFile()
{
String parent = getParent();
- return parent != null ? new File (parent) : null;
+ return parent != null ? new File(parent) : null;
}
/**
@@ -521,10 +524,7 @@
*/
public boolean isAbsolute()
{
- if (PlatformHelper.beginWithRootPathPrefix (path) > 0)
- return true;
- else
- return false;
+ return PlatformHelper.beginWithRootPathPrefix(path) > 0;
}
/**
@@ -540,7 +540,7 @@
public boolean isDirectory()
{
checkRead();
- return isDirectoryInternal (path);
+ return isDirectoryInternal(path);
}
/**
@@ -556,7 +556,7 @@
public boolean isFile()
{
checkRead();
- return isFileInternal (path);
+ return isFileInternal(path);
}
/**
@@ -573,10 +573,7 @@
public boolean isHidden()
{
// FIXME: this only works on UNIX
- if (getName().startsWith("."))
- return true;
- else
- return false;
+ return getName().startsWith(".");
}
/*
@@ -602,7 +599,7 @@
public long lastModified()
{
checkRead();
- return lastModifiedInternal (path);
+ return lastModifiedInternal(path);
}
/*
@@ -622,14 +619,14 @@
public long length()
{
checkRead();
- return lengthInternal (path);
+ return lengthInternal(path);
}
/*
* This native function actually produces the list of file in this
* directory
*/
- private native String[] listInternal (String dirname);
+ private native String[] listInternal(String dirname);
/**
* This method returns a array of String
's representing the
@@ -658,7 +655,7 @@
* @exception SecurityException If read access is not allowed to the
* directory by the SecurityManager
*/
- public String[] list (FilenameFilter filter)
+ public String[] list(FilenameFilter filter)
{
checkRead();
@@ -666,7 +663,8 @@
String list_path = PlatformHelper.removeTailSeparator(path);
File dir = new File(list_path);
- if (! dir.exists() || ! dir.isDirectory() ) return null;
+ if (! dir.exists() || ! dir.isDirectory())
+ return null;
String files[] = listInternal(list_path);
@@ -716,7 +714,7 @@
*/
public String[] list()
{
- return list (null);
+ return list(null);
}
/**
@@ -739,7 +737,7 @@
*/
public File[] listFiles()
{
- return listFiles ((FilenameFilter) null);
+ return listFiles((FilenameFilter) null);
}
/**
@@ -766,9 +764,9 @@
*
* @since 1.2
*/
- public File[] listFiles (FilenameFilter filter)
+ public File[] listFiles(FilenameFilter filter)
{
- String[] filelist = list (filter);
+ String[] filelist = list(filter);
if (filelist == null)
return null;
@@ -776,7 +774,7 @@
File[] fobjlist = new File [filelist.length];
for (int i = 0; i < filelist.length; i++)
- fobjlist [i] = new File (this, filelist [i]);
+ fobjlist [i] = new File(this, filelist [i]);
return fobjlist;
}
@@ -805,9 +803,9 @@
*
* @since 1.2
*/
- public File[] listFiles (FileFilter filter)
+ public File[] listFiles(FileFilter filter)
{
- File[] fobjlist = listFiles ((FilenameFilter) null);
+ File[] fobjlist = listFiles((FilenameFilter) null);
if (fobjlist == null)
return null;
@@ -859,20 +857,20 @@
try
{
- if (new File (abspath).isDirectory())
+ if (new File(abspath).isDirectory())
abspath = abspath + separator;
}
catch(Exception _) { }
String url_string = "file://" + abspath;
- return new URL (url_string);
+ return new URL(url_string);
}
/*
* This native method actually creates the directory
*/
- private native boolean mkdirInternal (String path);
+ private native boolean mkdirInternal(String path);
/**
* This method creates a directory for the path represented by this object.
@@ -885,8 +883,7 @@
public boolean mkdir()
{
checkWrite();
- String mk_path = PlatformHelper.removeTailSeparator (path);
- return mkdirInternal (mk_path);
+ return mkdirInternal(PlatformHelper.removeTailSeparator(path));
}
/**
@@ -920,7 +917,7 @@
/**
* This method is used to create a temporary file
*/
- private static native boolean createInternal (String name) throws IOException;
+ private static native boolean createInternal(String name) throws IOException;
/**
* This method creates a temporary file in the specified directory. If
@@ -952,30 +949,30 @@
*
* @since 1.2
*/
- public static File createTempFile (String prefix, String suffix,
+ public static File createTempFile(String prefix, String suffix,
File directory)
throws IOException
{
// Grab the system temp directory if necessary
if (directory == null)
{
- String dirname = System.getProperty ("java.io.tmpdir");
+ String dirname = System.getProperty("java.io.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 "
+ throw new IOException("System temporary directory "
+ directory.getName() + " does not exist.");
if (!directory.isDirectory())
- throw new IOException ("System temporary directory "
+ throw new IOException("System temporary directory "
+ directory.getName()
+ " is not really a directory.");
}
// Check if prefix is at least 3 characters long
if (prefix.length() < 3)
- throw new IllegalArgumentException ("Prefix too short: " + prefix);
+ throw new IllegalArgumentException("Prefix too short: " + prefix);
// Set default value of suffix
if (suffix == null)
@@ -995,7 +992,7 @@
do
{
String filename = prefix + System.currentTimeMillis() + suffix;
- file = new File (directory, filename);
+ file = new File(directory, filename);
}
while (file.exists());
}
@@ -1007,10 +1004,10 @@
if (prefix.length() >= 8)
throw new IllegalArgumentException("Prefix too long: " + prefix + "(valid length 3..7)");
- int mask = (int)(0x000000ffffFFFFL >> (long)(prefix.length() * 4));
+ int mask = (int) (0x000000ffffFFFFL >> (long) (prefix.length() * 4));
do
{
- int n = (int)(System.currentTimeMillis() & mask);
+ int n = (int) (System.currentTimeMillis() & mask);
String filename = prefix + java.lang.Integer.toHexString(n) + suffix;
file = new File(directory, filename);
}
@@ -1030,7 +1027,7 @@
/*
* This native method sets the permissions to make the file read only.
*/
- private native boolean setReadOnlyInternal (String path);
+ private native boolean setReadOnlyInternal(String path);
/**
* This method sets the file represented by this object to be read only.
@@ -1055,7 +1052,7 @@
// We still need to do a SecurityCheck since exists() only checks
// for read access
checkWrite();
- return setReadOnlyInternal (path);
+ return setReadOnlyInternal(path);
}
/**
@@ -1071,10 +1068,9 @@
*/
public static File[] listRoots()
{
- File[] f = new File[1];
- f[0] = new File("/");
-
- return f;
+ File[] roots = new File[1];
+ roots[0] = new File("/");
+ return roots;
}
/**
@@ -1104,10 +1100,10 @@
* this operation
* @exception IOException If an error occurs
*/
- public static File createTempFile (String prefix, String suffix)
+ public static File createTempFile(String prefix, String suffix)
throws IOException
{
- return createTempFile (prefix, suffix, null);
+ return createTempFile(prefix, suffix, null);
}
/**
@@ -1126,7 +1122,7 @@
*
* @since 1.2
*/
- public int compareTo (File other)
+ public int compareTo(File other)
{
String p1, p2;
@@ -1144,7 +1140,10 @@
return 0;
}
- return p1.compareTo (p2);
+ if (caseSensitive)
+ return p1.compareTo(p2);
+ else
+ return p1.compareToIgnoreCase(p2);
}
/**
@@ -1168,9 +1167,9 @@
*
* @since 1.2
*/
- public int compareTo (Object obj)
+ public int compareTo(Object obj)
{
- return compareTo ((File) obj);
+ return compareTo((File) obj);
}
/*
@@ -1190,17 +1189,17 @@
* @exception SecurityException If write access is not allowed to the
* file by the SecurityMananger
.
*/
- public synchronized boolean renameTo (File dest)
+ public synchronized boolean renameTo(File dest)
{
checkWrite();
// Call our native rename method
- return renameToInternal (path, dest.path);
+ return renameToInternal(path, dest.path);
}
/*
* This method does the actual setting of the modification time.
*/
- private native boolean setLastModifiedInternal (String path, long time);
+ private native boolean setLastModifiedInternal(String path, long time);
/**
* This method sets the modification time on the file to the specified
@@ -1218,13 +1217,13 @@
*
* @since 1.2
*/
- public boolean setLastModified (long time)
+ public boolean setLastModified(long time)
{
if (time < 0)
throw new IllegalArgumentException("Negative modification time: " + time);
checkWrite();
- return setLastModifiedInternal (path, time);
+ return setLastModifiedInternal(path, time);
}
private void checkWrite()
@@ -1233,7 +1232,7 @@
SecurityManager s = System.getSecurityManager();
if (s != null)
- s.checkWrite (path);
+ s.checkWrite(path);
}
private void checkRead()
@@ -1242,7 +1241,7 @@
SecurityManager s = System.getSecurityManager();
if (s != null)
- s.checkRead (path);
+ s.checkRead(path);
}
/**
@@ -1260,7 +1259,7 @@
// Check the SecurityManager
SecurityManager sm = System.getSecurityManager();
if (sm != null)
- sm.checkDelete (path);
+ sm.checkDelete(path);
// Sounds like we need to do some VM specific stuff here. We could delete
// the file in finalize() and set FinalizeOnExit to true, but delete on
@@ -1270,13 +1269,13 @@
return;
}
- private void writeObject (ObjectOutputStream oos) throws IOException
+ private void writeObject(ObjectOutputStream oos) throws IOException
{
oos.defaultWriteObject();
- oos.writeChar (separatorChar);
+ oos.writeChar(separatorChar);
}
- private void readObject (ObjectInputStream ois)
+ private void readObject(ObjectInputStream ois)
throws ClassNotFoundException, IOException
{
ois.defaultReadObject();
@@ -1286,7 +1285,7 @@
char oldSeparatorChar = ois.readChar();
if (oldSeparatorChar != separatorChar)
- path = path.replace (oldSeparatorChar, separatorChar);
+ path = path.replace(oldSeparatorChar, separatorChar);
}
} // class File