summaryrefslogtreecommitdiff
path: root/libjava/classpath/java/io/File.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/java/io/File.java')
-rw-r--r--libjava/classpath/java/io/File.java447
1 files changed, 223 insertions, 224 deletions
diff --git a/libjava/classpath/java/io/File.java b/libjava/classpath/java/io/File.java
index f023310449f..4f670e147fe 100644
--- a/libjava/classpath/java/io/File.java
+++ b/libjava/classpath/java/io/File.java
@@ -8,7 +8,7 @@ GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@@ -76,12 +76,12 @@ public class File implements Serializable, Comparable<File>
/**
* This is the first character of the file separator string. On many
- * hosts (for example, on the GNU system), this represents the entire
+ * hosts (for example, on the GNU system), this represents the entire
* separator string. The complete separator string is obtained from the
* <code>file.separator</code>system property.
*/
public static final char separatorChar = separator.charAt(0);
-
+
/**
* This is the string that is used to separate the host name from the
* path name in paths that include the host name. It is the value of
@@ -89,7 +89,7 @@ public class File implements Serializable, Comparable<File>
*/
public static final String pathSeparator
= SystemProperties.getProperty("path.separator");
-
+
/**
* This is the first character of the string used to separate the host name
* from the path name in paths that include a host. The separator string
@@ -102,17 +102,17 @@ public class File implements Serializable, Comparable<File>
* may be an absolute or relative path name.
*/
private String path;
-
-
+
+
/**
* The time (millisecond), when the last temporary file was created.
*/
private static long last_tmp;
-
+
/**
* The number of files, created during the current millisecond.
*/
- private static int n_created;
+ private static int n_created;
/**
* This method tests whether or not the current thread is allowed to
@@ -121,10 +121,10 @@ public class File implements Serializable, Comparable<File>
* (if any) allows access to the file via it's <code>checkRead</code>
* method 3) the file is readable.
*
- * @return <code>true</code> if reading is allowed,
+ * @return <code>true</code> if reading is allowed,
* <code>false</code> otherwise
*
- * @exception SecurityException If the <code>SecurityManager</code>
+ * @exception SecurityException If the <code>SecurityManager</code>
* does not allow access to the file
*/
public boolean canRead()
@@ -144,17 +144,17 @@ public class File implements Serializable, Comparable<File>
* whether or not a non-existent file can be created, check the parent
* directory for write access.
*
- * @return <code>true</code> if writing is allowed, <code>false</code>
+ * @return <code>true</code> if writing is allowed, <code>false</code>
* otherwise
*
- * @exception SecurityException If the <code>SecurityManager</code>
+ * @exception SecurityException If the <code>SecurityManager</code>
* does not allow access to the file
*/
public boolean canWrite()
{
// First do a SecurityCheck before doing anything else.
checkWrite();
-
+
// Test for existence. This is required by the spec
if (! VMFile.exists(path))
return false;
@@ -172,10 +172,10 @@ public class File implements Serializable, Comparable<File>
* (if any) allows access to the file via it's <code>checkExec</code>
* method 3) the file is executable.
*
- * @return <code>true</code> if execution is allowed,
+ * @return <code>true</code> if execution is allowed,
* <code>false</code> otherwise
*
- * @exception SecurityException If the <code>SecurityManager</code>
+ * @exception SecurityException If the <code>SecurityManager</code>
* does not allow access to the file
*/
public boolean canExecute()
@@ -184,7 +184,7 @@ public class File implements Serializable, Comparable<File>
return false;
checkExec();
-
+
return VMFile.canExecute(path);
}
@@ -214,7 +214,7 @@ public class File implements Serializable, Comparable<File>
* This method deletes the file represented by this object. If this file
* is a directory, it must be empty in order for the delete to succeed.
*
- * @return <code>true</code> if the file was deleted, <code>false</code>
+ * @return <code>true</code> if the file was deleted, <code>false</code>
* otherwise
*
* @exception SecurityException If deleting of the file is not allowed
@@ -222,33 +222,33 @@ public class File implements Serializable, Comparable<File>
public synchronized boolean delete()
{
SecurityManager s = System.getSecurityManager();
-
+
if (s != null)
s.checkDelete(path);
-
+
return VMFile.delete(path);
}
/**
- * This method tests two <code>File</code> objects for equality by
+ * This method tests two <code>File</code> objects for equality by
* comparing the path of the specified <code>File</code> against the path
* of this object. The two objects are equal if an only if 1) The
* argument is not null 2) The argument is a <code>File</code> object and
* 3) The path of the <code>File</code>argument is equal to the path
* of this object.
* <p>
- * The paths of the files are determined by calling the
+ * The paths of the files are determined by calling the
* <code>getPath()</code>
* method on each object.
*
- * @return <code>true</code> if the two objects are equal,
+ * @return <code>true</code> if the two objects are equal,
* <code>false</code> otherwise.
*/
public boolean equals(Object obj)
{
if (! (obj instanceof File))
return false;
-
+
File other = (File) obj;
if (VMFile.IS_CASE_SENSITIVE)
@@ -281,7 +281,7 @@ public class File implements Serializable, Comparable<File>
{
path = normalizePath (name);
}
-
+
// Remove duplicate and redundant separator characters.
private String normalizePath(String p)
{
@@ -290,12 +290,12 @@ public class File implements Serializable, Comparable<File>
if (separatorChar == '\\')
{
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);
+ // 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);
@@ -310,25 +310,25 @@ public class File implements Serializable, Comparable<File>
// Ignore trailing separator (though on Windows "a:\", for
// example, is a valid and minimal path).
if (plen > 1 && p.charAt (plen - 1) == separatorChar)
- {
- if (! (separatorChar == '\\' && ((plen == 3 && p.charAt(1) == ':')
+ {
+ if (! (separatorChar == '\\' && ((plen == 3 && p.charAt(1) == ':')
|| (plen == 2 && p.charAt(0) == separatorChar))))
- return p.substring (0, plen - 1);
- }
- else
- return p;
+ return p.substring (0, plen - 1);
+ }
+ else
+ return p;
}
-
+
CPStringBuilder newpath = new CPStringBuilder(plen);
int last = 0;
while (dupIndex != -1)
{
newpath.append(p.substring(last, dupIndex));
- // Ignore the duplicate path characters.
- while (p.charAt(dupIndex) == separatorChar)
- {
- dupIndex++;
- if (dupIndex == plen)
+ // Ignore the duplicate path characters.
+ while (p.charAt(dupIndex) == separatorChar)
+ {
+ dupIndex++;
+ if (dupIndex == plen)
{
if ((separatorChar == '\\'
&& newpath.length() == 2
@@ -337,14 +337,14 @@ public class File implements Serializable, Comparable<File>
{
newpath.append(separatorChar);
}
- return newpath.toString();
+ return newpath.toString();
}
- }
- newpath.append(separatorChar);
- last = dupIndex;
- dupIndex = p.indexOf(dupSeparator, last);
+ }
+ newpath.append(separatorChar);
+ last = dupIndex;
+ dupIndex = p.indexOf(dupSeparator, last);
}
-
+
// Again, ignore possible trailing separator (except special cases
// like "a:\" on Windows).
int end;
@@ -360,10 +360,10 @@ public class File implements Serializable, Comparable<File>
else
end = plen;
newpath.append(p.substring(last, end));
-
+
return newpath.toString();
}
-
+
/**
* This method initializes a new <code>File</code> object to represent
* a file in the specified named directory. The path name to the file
@@ -380,35 +380,35 @@ public class File implements Serializable, Comparable<File>
throw new NullPointerException();
if (dirPath != null)
{
- if (dirPath.length() > 0)
- {
- // Try to be smart about the number of separator characters.
- if (dirPath.charAt(dirPath.length() - 1) == separatorChar
- || name.length() == 0)
- path = normalizePath(dirPath + name);
- else
- path = normalizePath(dirPath + separatorChar + name);
- }
- else
- {
- // If dirPath is empty, use a system dependant
- // default prefix.
- // Note that the leading separators in name have
- // to be chopped off, to prevent them forming
- // a UNC prefix on Windows.
- if (separatorChar == '\\' /* TODO use ON_WINDOWS */)
- {
- int skip = 0;
- while(name.length() > skip
- && (name.charAt(skip) == separatorChar
- || name.charAt(skip) == '/'))
- {
- skip++;
- }
- name = name.substring(skip);
- }
- path = normalizePath(separatorChar + name);
- }
+ if (dirPath.length() > 0)
+ {
+ // Try to be smart about the number of separator characters.
+ if (dirPath.charAt(dirPath.length() - 1) == separatorChar
+ || name.length() == 0)
+ path = normalizePath(dirPath + name);
+ else
+ path = normalizePath(dirPath + separatorChar + name);
+ }
+ else
+ {
+ // If dirPath is empty, use a system dependant
+ // default prefix.
+ // Note that the leading separators in name have
+ // to be chopped off, to prevent them forming
+ // a UNC prefix on Windows.
+ if (separatorChar == '\\' /* TODO use ON_WINDOWS */)
+ {
+ int skip = 0;
+ while(name.length() > skip
+ && (name.charAt(skip) == separatorChar
+ || name.charAt(skip) == '/'))
+ {
+ skip++;
+ }
+ name = name.substring(skip);
+ }
+ path = normalizePath(separatorChar + name);
+ }
}
else
path = normalizePath(name);
@@ -439,10 +439,10 @@ public class File implements Serializable, Comparable<File>
public File(URI uri)
{
if (uri == null)
- throw new NullPointerException("uri is null");
+ throw new NullPointerException("uri is null");
if (!uri.getScheme().equals("file"))
- throw new IllegalArgumentException("invalid uri protocol");
+ throw new IllegalArgumentException("invalid uri protocol");
String name = uri.getPath();
if (name == null)
@@ -489,7 +489,7 @@ public class File implements Serializable, Comparable<File>
* "." and "..", and symbolic links.
* <p>
* Note that this method, unlike the other methods which return path
- * names, can throw an IOException. This is because native method
+ * names, can throw an IOException. This is because native method
* might be required in order to resolve the canonical path
*
* @exception IOException If an error occurs
@@ -499,11 +499,11 @@ public class File implements Serializable, Comparable<File>
// On Windows, getAbsolutePath might end up calling us, so we
// have to special case that call to avoid infinite recursion.
if (separatorChar == '\\' && path.length() == 2 &&
- ((path.charAt(0) >= 'a' && path.charAt(0) <= 'z') ||
- (path.charAt(0) >= 'A' && path.charAt(0) <= 'Z')) &&
- path.charAt(1) == ':')
+ ((path.charAt(0) >= 'a' && path.charAt(0) <= 'z') ||
+ (path.charAt(0) >= 'A' && path.charAt(0) <= 'Z')) &&
+ path.charAt(1) == ':')
{
- return VMFile.toCanonicalForm(path);
+ return VMFile.toCanonicalForm(path);
}
// Call getAbsolutePath first to make sure that we do the
// current directory handling, because the native code
@@ -536,7 +536,7 @@ public class File implements Serializable, Comparable<File>
*/
public String getName()
{
- return VMFile.getName(path);
+ return VMFile.getName(path);
}
/**
@@ -551,11 +551,11 @@ public class File implements Serializable, Comparable<File>
{
String prefix = null;
int nameSeqIndex = 0;
-
+
if (path.equals(""))
return null;
- // The "prefix", if present, is the leading "/" on UNIX and
+ // The "prefix", if present, is the leading "/" on UNIX and
// either the drive specifier (e.g. "C:") or the leading "\\"
// of a UNC network path on Windows.
if (separatorChar == '/' && path.charAt (0) == '/')
@@ -575,7 +575,7 @@ public class File implements Serializable, Comparable<File>
}
}
- // According to the JDK docs, the returned parent path is the
+ // According to the JDK docs, the returned parent path is the
// portion of the name sequence before the last separator
// character, if found, prefixed by the prefix, otherwise null.
if (nameSeqIndex < path.length())
@@ -586,7 +586,7 @@ public class File implements Serializable, Comparable<File>
return prefix;
else if (last == (nameSeq.length() - 1))
// Note: The path would not have a trailing separator
- // except for cases like "C:\" on Windows (see
+ // except for cases like "C:\" on Windows (see
// normalizePath( )), where Sun's JRE 1.4 returns null.
return null;
else if (last == 0)
@@ -598,8 +598,8 @@ public class File implements Serializable, Comparable<File>
return nameSeq.substring (0, last);
}
else
- // Sun's JRE 1.4 returns null if the prefix is the only
- // component of the path - so "/" gives null on UNIX and
+ // Sun's JRE 1.4 returns null if the prefix is the only
+ // component of the path - so "/" gives null on UNIX and
// "C:", "\\", etc. return null on Windows.
return null;
}
@@ -608,7 +608,7 @@ public class File implements Serializable, Comparable<File>
* This method returns a <code>File</code> object representing the parent
* file of this one.
*
- * @return 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.
*
@@ -652,7 +652,7 @@ public class File implements Serializable, Comparable<File>
* by system. As an example, on GNU systems, a path is absolute if it starts
* with a "/".
*
- * @return <code>true</code> if this object represents an absolute
+ * @return <code>true</code> if this object represents an absolute
* file name, <code>false</code> otherwise.
*/
public boolean isAbsolute()
@@ -664,7 +664,7 @@ public class File implements Serializable, Comparable<File>
* This method tests whether or not the file represented by this object
* is a directory. In order for this method to return <code>true</code>,
* the file represented by this object must exist and be a directory.
- *
+ *
* @return <code>true</code> if this file is a directory, <code>false</code>
* otherwise
*
@@ -673,7 +673,7 @@ public class File implements Serializable, Comparable<File>
public boolean isDirectory()
{
checkRead();
- return VMFile.isDirectory(path);
+ return VMFile.isDirectory(path);
}
/**
@@ -681,7 +681,7 @@ public class File implements Serializable, Comparable<File>
* is a "plain" file. A file is a plain file if and only if it 1) Exists,
* 2) Is not a directory or other type of special file.
*
- * @return <code>true</code> if this is a plain file, <code>false</code>
+ * @return <code>true</code> if this is a plain file, <code>false</code>
* otherwise
*
* @exception SecurityException If reading of the file is not permitted
@@ -713,7 +713,7 @@ public class File implements Serializable, Comparable<File>
* time value returned is an abstract value that should not be interpreted
* as a specified time value. It is only useful for comparing to other
* such time values returned on the same system. In that case, the larger
- * value indicates a more recent modification time.
+ * value indicates a more recent modification time.
* <p>
* If the file does not exist, then a value of 0 is returned.
*
@@ -759,13 +759,13 @@ public class File implements Serializable, Comparable<File>
* directory. If read access to the directory is denied, an exception
* will be thrown.
*
- * @param filter An object which will identify files to exclude from
+ * @param filter An object which will identify files to exclude from
* the directory listing.
*
- * @return An array of files in the directory, or <code>null</code>
+ * @return An array of files in the directory, or <code>null</code>
* if this object does not represent a valid directory.
- *
- * @exception SecurityException If read access is not allowed to the
+ *
+ * @exception SecurityException If read access is not allowed to the
* directory by the <code>SecurityManager</code>
*/
public String[] list(FilenameFilter filter)
@@ -774,10 +774,10 @@ public class File implements Serializable, Comparable<File>
if (!exists() || !isDirectory())
return null;
-
+
// Get the list of files
String files[] = VMFile.list(path);
-
+
// Check if an error occured in listInternal().
// This is an unreadable directory, pretend there is nothing inside.
if (files == null)
@@ -785,15 +785,15 @@ public class File implements Serializable, Comparable<File>
if (filter == null)
return files;
-
+
// Apply the filter
int count = 0;
for (int i = 0; i < files.length; i++)
{
if (filter.accept(this, files[i]))
- ++count;
+ ++count;
else
- files[i] = null;
+ files[i] = null;
}
String[] retfiles = new String[count];
@@ -817,10 +817,10 @@ public class File implements Serializable, Comparable<File>
* directory. If read access to the directory is denied, an exception
* will be thrown.
*
- * @return An array of files in the directory, or <code>null</code> if
+ * @return An array of files in the directory, or <code>null</code> if
* this object does not represent a valid directory.
- *
- * @exception SecurityException If read access is not allowed to the
+ *
+ * @exception SecurityException If read access is not allowed to the
* directory by the <code>SecurityManager</code>
*/
public String[] list()
@@ -850,14 +850,14 @@ public class File implements Serializable, Comparable<File>
{
return listFiles((FilenameFilter) null);
}
-
+
/**
* This method returns an array of <code>File</code> objects representing
* all the files in the directory represented by this object. If this
* object does not represent a directory, <code>null</code> is returned.
* Each of the returned <code>File</code> object is constructed with this
* object as its parent.
- * <p>
+ * <p>
* In this form of the <code>listFiles()</code> method, a filter is specified
* that allows the caller to control which files are returned in the
* list. The <code>FilenameFilter</code> specified is called for each
@@ -878,7 +878,7 @@ public class File implements Serializable, Comparable<File>
public File[] listFiles(FilenameFilter filter)
{
String[] filelist = list(filter);
-
+
if (filelist == null)
return null;
@@ -896,7 +896,7 @@ public class File implements Serializable, Comparable<File>
* object does not represent a directory, <code>null</code> is returned.
* Each of the returned <code>File</code> object is constructed with this
* object as its parent.
- * <p>
+ * <p>
* In this form of the <code>listFiles()</code> method, a filter is specified
* that allows the caller to control which files are returned in the
* list. The <code>FileFilter</code> specified is called for each
@@ -958,13 +958,13 @@ public class File implements Serializable, Comparable<File>
public URI toURI()
{
String abspath = getAbsolutePath();
-
+
if (isDirectory() || path.equals(""))
abspath = abspath + separatorChar;
if (separatorChar == '\\')
abspath = separatorChar + abspath;
-
+
try
{
return new URI("file", null, null, -1,
@@ -975,7 +975,7 @@ public class File implements Serializable, Comparable<File>
{
// Can't happen.
throw (InternalError) new InternalError("Unconvertible file: "
- + this).initCause(use);
+ + this).initCause(use);
}
}
@@ -986,7 +986,7 @@ public class File implements Serializable, Comparable<File>
*
* @return A <code>URL</code> for this object.
*
- * @exception MalformedURLException If the URL cannot be created
+ * @exception MalformedURLException If the URL cannot be created
* successfully.
*/
public URL toURL() throws MalformedURLException
@@ -998,7 +998,7 @@ public class File implements Serializable, Comparable<File>
/**
* This method creates a directory for the path represented by this object.
*
- * @return <code>true</code> if the directory was created,
+ * @return <code>true</code> if the directory was created,
* <code>false</code> otherwise
*
* @exception SecurityException If write access is not allowed to this file
@@ -1013,7 +1013,7 @@ public class File implements Serializable, Comparable<File>
* This method creates a directory for the path represented by this file.
* It will also create any intervening parent directories if necessary.
*
- * @return <code>true</code> if the directory was created,
+ * @return <code>true</code> if the directory was created,
* <code>false</code> otherwise
*
* @exception SecurityException If write access is not allowed to this file
@@ -1025,7 +1025,7 @@ public class File implements Serializable, Comparable<File>
{
return mkdir();
}
-
+
File f = new File(parent);
if (!f.exists())
{
@@ -1038,12 +1038,12 @@ public class File implements Serializable, Comparable<File>
}
/**
- * This method creates a temporary file in the specified directory. If
- * the directory name is null, then this method uses the system temporary
- * directory. The files created are guaranteed not to currently exist and
- * the same file name will never be used twice in the same virtual
- * machine instance.
- * The system temporary directory is determined by examinging the
+ * This method creates a temporary file in the specified directory. If
+ * the directory name is null, then this method uses the system temporary
+ * directory. The files created are guaranteed not to currently exist and
+ * the same file name will never be used twice in the same virtual
+ * machine instance.
+ * The system temporary directory is determined by examinging the
* <code>java.io.tmpdir</code> system property.
* <p>
* The <code>prefix</code> parameter is a sequence of at least three
@@ -1057,18 +1057,18 @@ public class File implements Serializable, Comparable<File>
*
* @param prefix The character prefix to use in generating the path name.
* @param suffix The character suffix to use in generating the path name.
- * @param directory The directory to create the file in, or
+ * @param directory The directory to create the file in, or
* <code>null</code> for the default temporary directory
*
* @exception IllegalArgumentException If the patterns is not valid
- * @exception SecurityException If there is no permission to perform
+ * @exception SecurityException If there is no permission to perform
* this operation
* @exception IOException If an error occurs
*
* @since 1.2
*/
public static synchronized File createTempFile(String prefix, String suffix,
- File directory)
+ File directory)
throws IOException
{
// Grab the system temp directory if necessary
@@ -1076,8 +1076,8 @@ public class File implements Serializable, Comparable<File>
{
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);
if (! VMFile.exists(directory.path))
throw new IOException("System temporary directory "
@@ -1099,7 +1099,7 @@ public class File implements Serializable, Comparable<File>
// Now identify a file name and make sure it doesn't exist.
File file;
if (!VMFile.IS_DOS_8_3)
- {
+ {
do
{
long now = System.currentTimeMillis();
@@ -1111,7 +1111,7 @@ public class File implements Serializable, Comparable<File>
}
else
n_created++;
-
+
String name = Long.toHexString(now);
if (n_created > 0)
name += '_'+Integer.toHexString(n_created);
@@ -1143,16 +1143,16 @@ public class File implements Serializable, Comparable<File>
// Now create the file and return our file object
// XXX - FIXME race condition.
- VMFile.create(file.getAbsolutePath());
+ VMFile.create(file.getAbsolutePath());
return file;
}
/**
* This method sets the owner's read permission for the File represented by
* this object.
- *
+ *
* It is the same as calling <code>setReadable(readable, true)</code>.
- *
+ *
* @param <code>readable</code> <code>true</code> to set read permission,
* <code>false</code> to unset the read permission.
* @return <code>true</code> if the file permissions are changed,
@@ -1165,21 +1165,21 @@ public class File implements Serializable, Comparable<File>
{
return setReadable(readable, true);
}
-
+
/**
* This method sets the read permissions for the File represented by
* this object.
- *
+ *
* If <code>ownerOnly</code> is set to <code>true</code> then only the
* read permission bit for the owner of the file is changed.
- *
+ *
* If <code>ownerOnly</code> is set to <code>false</code>, the file
* permissions are changed so that the file can be read by everyone.
- *
+ *
* On unix like systems this sets the <code>user</code>, <code>group</code>
* and <code>other</code> read bits and is equal to call
* <code>chmod a+r</code> on the file.
- *
+ *
* @param <code>readable</code> <code>true</code> to set read permission,
* <code>false</code> to unset the read permission.
* @param <code>ownerOnly</code> <code>true</code> to set read permission
@@ -1195,13 +1195,13 @@ public class File implements Serializable, Comparable<File>
checkWrite();
return VMFile.setReadable(path, readable, ownerOnly);
}
-
+
/**
* This method sets the owner's write permission for the File represented by
* this object.
- *
- * It is the same as calling <code>setWritable(readable, true)</code>.
- *
+ *
+ * It is the same as calling <code>setWritable(readable, true)</code>.
+ *
* @param <code>writable</code> <code>true</code> to set write permission,
* <code>false</code> to unset write permission.
* @return <code>true</code> if the file permissions are changed,
@@ -1214,25 +1214,25 @@ public class File implements Serializable, Comparable<File>
{
return setWritable(writable, true);
}
-
+
/**
* This method sets the write permissions for the File represented by
* this object.
- *
+ *
* If <code>ownerOnly</code> is set to <code>true</code> then only the
* write permission bit for the owner of the file is changed.
- *
+ *
* If <code>ownerOnly</code> is set to <code>false</code>, the file
* permissions are changed so that the file can be written by everyone.
- *
+ *
* On unix like systems this set the <code>user</code>, <code>group</code>
* and <code>other</code> write bits and is equal to call
* <code>chmod a+w</code> on the file.
- *
+ *
* @param <code>writable</code> <code>true</code> to set write permission,
* <code>false</code> to unset write permission.
* @param <code>ownerOnly</code> <code>true</code> to set write permission
- * for owner only, <code>false</code> for all.
+ * for owner only, <code>false</code> for all.
* @return <code>true</code> if the file permissions are changed,
* <code>false</code> otherwise.
* @exception SecurityException If write access of the file is not permitted.
@@ -1244,13 +1244,13 @@ public class File implements Serializable, Comparable<File>
checkWrite();
return VMFile.setWritable(path, writable, ownerOnly);
}
-
+
/**
* This method sets the owner's execute permission for the File represented
* by this object.
- *
- * It is the same as calling <code>setExecutable(readable, true)</code>.
- *
+ *
+ * It is the same as calling <code>setExecutable(readable, true)</code>.
+ *
* @param <code>executable</code> <code>true</code> to set execute permission,
* <code>false</code> to unset execute permission.
* @return <code>true</code> if the file permissions are changed,
@@ -1259,29 +1259,29 @@ public class File implements Serializable, Comparable<File>
* @see #setExecutable(boolean, boolean)
* @since 1.6
*/
- public boolean setExecutable(boolean executable)
+ public boolean setExecutable(boolean executable)
{
return setExecutable(executable, true);
}
-
+
/**
* This method sets the execute permissions for the File represented by
* this object.
- *
+ *
* If <code>ownerOnly</code> is set to <code>true</code> then only the
* execute permission bit for the owner of the file is changed.
- *
+ *
* If <code>ownerOnly</code> is set to <code>false</code>, the file
* permissions are changed so that the file can be executed by everyone.
- *
+ *
* On unix like systems this set the <code>user</code>, <code>group</code>
* and <code>other</code> write bits and is equal to call
* <code>chmod a+x</code> on the file.
- *
+ *
* @param <code>executable</code> <code>true</code> to set write permission,
* <code>false</code> to unset write permission.
* @param <code>ownerOnly</code> <code>true</code> to set write permission
- * for owner only, <code>false</code> for all.
+ * for owner only, <code>false</code> for all.
* @return <code>true</code> if the file permissions are changed,
* <code>false</code> otherwise.
* @exception SecurityException If write access of the file is not permitted.
@@ -1296,8 +1296,8 @@ public class File implements Serializable, Comparable<File>
/**
* Get the total space for the partition pointed by this file path, in bytes.
- *
- * @return the total number of bytes in this partition.
+ *
+ * @return the total number of bytes in this partition.
* @since 1.6
*/
public long getTotalSpace()
@@ -1307,14 +1307,14 @@ public class File implements Serializable, Comparable<File>
if (s != null)
s.checkPermission(new RuntimePermission("getFileSystemAttributes"));
checkRead();
-
+
return VMFile.getTotalSpace(path);
}
-
+
/**
* Get the free space in the partition pointed by this file path, in bytes.
- *
- * @return the number of free bytes in this partition.
+ *
+ * @return the number of free bytes in this partition.
* @since 1.6
*/
public long getFreeSpace()
@@ -1324,25 +1324,25 @@ public class File implements Serializable, Comparable<File>
if (s != null)
s.checkPermission(new RuntimePermission("getFileSystemAttributes"));
checkRead();
-
+
return VMFile.getFreeSpace(path);
}
-
+
/**
* Get the usable space in the partition pointed by this file path, in bytes.
* This is not necessarily the same as the number returned by
* {@link #getFreeSpace()}.
- *
+ *
* <strong>Implementation note</strong>: Unlike the RI, on Linux and UNIX
* like systems this methods take into account the reserved space for the
* "root" user. This means that the returned results will be a little
* different if a normal user or root perform the query.
- *
+ *
* Also, the bytes returned should be interpreted as an hint, and may be
* different at each call of this method or even right after the method
* returns.
- *
- * @return the number of usable bytes in this partition.
+ *
+ * @return the number of usable bytes in this partition.
* @since 1.6
*/
public long getUsableSpace()
@@ -1352,18 +1352,18 @@ public class File implements Serializable, Comparable<File>
if (s != null)
s.checkPermission(new RuntimePermission("getFileSystemAttributes"));
checkRead();
-
+
// root users can use the reserved extra space
String user = System.getProperty("user.name");
if (user != null && user.equals("root"))
return VMFile.getFreeSpace(path);
-
+
return VMFile.getUsableSpace(path);
}
-
+
/**
* This method sets the file represented by this object to be read only.
- * A read only file or directory cannot be modified. Please note that
+ * A read only file or directory cannot be modified. Please note that
* GNU systems allow read only files to be deleted if the directory it
* is contained in is writable.
*
@@ -1401,44 +1401,44 @@ public class File implements Serializable, Comparable<File>
public static File[] listRoots()
{
File[] roots = VMFile.listRoots();
-
+
SecurityManager s = System.getSecurityManager();
if (s != null)
{
- // Only return roots to which the security manager permits read access.
- int count = roots.length;
- for (int i = 0; i < roots.length; i++)
- {
- try
- {
- s.checkRead (roots[i].path);
- }
- catch (SecurityException sx)
- {
- roots[i] = null;
- count--;
- }
- }
- if (count != roots.length)
- {
- File[] newRoots = new File[count];
- int k = 0;
- for (int i = 0; i < roots.length; i++)
- {
- if (roots[i] != null)
- newRoots[k++] = roots[i];
- }
- roots = newRoots;
- }
+ // Only return roots to which the security manager permits read access.
+ int count = roots.length;
+ for (int i = 0; i < roots.length; i++)
+ {
+ try
+ {
+ s.checkRead (roots[i].path);
+ }
+ catch (SecurityException sx)
+ {
+ roots[i] = null;
+ count--;
+ }
+ }
+ if (count != roots.length)
+ {
+ File[] newRoots = new File[count];
+ int k = 0;
+ for (int i = 0; i < roots.length; i++)
+ {
+ if (roots[i] != null)
+ newRoots[k++] = roots[i];
+ }
+ roots = newRoots;
+ }
}
return roots;
}
/**
- * This method creates a temporary file in the system temporary directory.
+ * This method creates a temporary file in the system temporary directory.
* The files created are guaranteed not to currently exist and the same file
* name will never be used twice in the same virtual machine instance. The
- * system temporary directory is determined by examinging the
+ * system temporary directory is determined by examinging the
* <code>java.io.tmpdir</code> system property.
* <p>
* The <code>prefix</code> parameter is a sequence of at least three
@@ -1450,14 +1450,14 @@ public class File implements Serializable, Comparable<File>
* If a <code>SecurityManager</code> exists, then its <code>checkWrite</code>
* method is used to verify that this operation is permitted.
* <p>
- * This method is identical to calling
+ * This method is identical to calling
* <code>createTempFile(prefix, suffix, null)</code>.
*
* @param prefix The character prefix to use in generating the path name.
* @param suffix The character suffix to use in generating the path name.
*
* @exception IllegalArgumentException If the prefix or suffix are not valid.
- * @exception SecurityException If there is no permission to perform
+ * @exception SecurityException If there is no permission to perform
* this operation
* @exception IOException If an error occurs
*/
@@ -1470,13 +1470,13 @@ public class File implements Serializable, Comparable<File>
/**
* This method compares the specified <code>File</code> to this one
* to test for equality. It does this by comparing the canonical path names
- * of the files.
+ * of the files.
* <p>
* The canonical paths of the files are determined by calling the
* <code>getCanonicalPath</code> method on each object.
* <p>
* This method returns a 0 if the specified <code>Object</code> is equal
- * to this one, a negative value if it is less than this one
+ * to this one, a negative value if it is less than this one
* a positive value if it is greater than this one.
*
* @return An integer as described above
@@ -1497,10 +1497,10 @@ public class File implements Serializable, Comparable<File>
*
* @param dest The <code>File</code> object representing the target name
*
- * @return <code>true</code> if the rename succeeds, <code>false</code>
+ * @return <code>true</code> if the rename succeeds, <code>false</code>
* otherwise.
*
- * @exception SecurityException If write access is not allowed to the
+ * @exception SecurityException If write access is not allowed to the
* file by the <code>SecurityMananger</code>.
*/
public synchronized boolean renameTo(File dest)
@@ -1527,7 +1527,7 @@ public class File implements Serializable, Comparable<File>
*
* @since 1.2
*/
- public boolean setLastModified(long time)
+ public boolean setLastModified(long time)
{
if (time < 0)
throw new IllegalArgumentException("Negative modification time: " + time);
@@ -1540,7 +1540,7 @@ public class File implements Serializable, Comparable<File>
{
// Check the SecurityManager
SecurityManager s = System.getSecurityManager();
-
+
if (s != null)
s.checkWrite(path);
}
@@ -1549,7 +1549,7 @@ public class File implements Serializable, Comparable<File>
{
// Check the SecurityManager
SecurityManager s = System.getSecurityManager();
-
+
if (s != null)
s.checkRead(path);
}
@@ -1558,12 +1558,12 @@ public class File implements Serializable, Comparable<File>
{
// Check the SecurityManager
SecurityManager s = System.getSecurityManager();
-
+
if (s != null)
s.checkExec(path);
}
-
- /**
+
+ /**
* 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
@@ -1571,7 +1571,7 @@ public class File implements Serializable, Comparable<File>
*
* @exception SecurityException If deleting of the file is not allowed
*
- * @since 1.2
+ * @since 1.2
*/
public void deleteOnExit()
{
@@ -1597,10 +1597,9 @@ public class File implements Serializable, Comparable<File>
// If the file was from an OS with a different dir separator,
// fixup the path to use the separator on this OS.
char oldSeparatorChar = ois.readChar();
-
+
if (oldSeparatorChar != separatorChar)
path = path.replace(oldSeparatorChar, separatorChar);
}
-
-} // class File
+} // class File