System.loadLibrary ("javaio");
}
- init_native ();
+ init_native();
}
// Native function called at class initialization. This should should
// We keep a counter for use by createTempFile. We choose the first
// value randomly to try to avoid clashes with other VMs.
- private static long counter = Double.doubleToLongBits (Math.random ());
+ private static long counter = Double.doubleToLongBits (Math.random());
/**
* This method tests whether or not the current thread is allowed to
* @exception SecurityException If the <code>SecurityManager</code>
* does not allow access to the file
*/
- public boolean canRead ()
+ public boolean canRead()
{
- checkRead ();
+ checkRead();
return _access (READ);
}
* @exception SecurityException If the <code>SecurityManager</code>
* does not allow access to the file
*/
- public boolean canWrite ()
+ public boolean canWrite()
{
- checkWrite ();
+ checkWrite();
return _access (WRITE);
}
*/
public boolean createNewFile() throws IOException
{
- checkWrite ();
+ checkWrite();
return performCreate();
}
/*
* This native method handles the actual deleting of the file
*/
- private native boolean performDelete ();
+ private native boolean performDelete();
/**
* This method deletes the file represented by this object. If this file
*
* @exception SecurityException If deleting of the file is not allowed
*/
- public synchronized boolean delete ()
+ public synchronized boolean delete()
{
- SecurityManager s = System.getSecurityManager ();
+ SecurityManager s = System.getSecurityManager();
if (s != null)
s.checkDelete (path);
- return performDelete ();
+ return performDelete();
}
/**
*/
public boolean equals (Object obj)
{
+ if (obj == null)
+ return false;
+
if (! (obj instanceof File))
return false;
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);
}
/**
*
* @exception SecurityException If reading of the file is not permitted
*/
- public boolean exists ()
+ public boolean exists()
{
- checkRead ();
+ checkRead();
return _access (EXISTS);
}
public File (String dirPath, String name)
{
if (name == null)
- throw new NullPointerException ();
+ throw new NullPointerException();
if (dirPath != null && dirPath.length() > 0)
{
// Try to be smart about the number of separator characters.
*
* @return The absolute path of this file
*/
- public String getAbsolutePath ()
+ public String getAbsolutePath()
{
- if (isAbsolute ())
+ if (isAbsolute())
return path;
else if (separatorChar == '\\'
- && path.length () > 0 && path.charAt (0) == '\\')
+ && path.length() > 0 && path.charAt (0) == '\\')
{
// On Windows, even if the path starts with a '\\' it is not
// really absolute until we prefix the drive specifier from
return System.getProperty ("user.dir").substring (0, 2) + path;
}
else if (separatorChar == '\\'
- && path.length () > 1 && path.charAt (1) == ':'
+ && path.length() > 1 && path.charAt (1) == ':'
&& ((path.charAt (0) >= 'a' && path.charAt (0) <= 'z')
|| (path.charAt (0) >= 'A' && path.charAt (0) <= 'Z')))
{
String drvDir = null;
try
{
- drvDir = new File (path.substring (0, 2)).getCanonicalPath ();
+ drvDir = new File (path.substring (0, 2)).getCanonicalPath();
}
catch (IOException e)
{
// Note: this would return "C:\\." for the path "C:.", if "\"
// is the working folder on the C drive, but this is
// consistent with what Sun's JRE 1.4.1.01 actually returns!
- if (path.length () > 2)
- return drvDir + '\\' + path.substring (2, path.length ());
+ if (path.length() > 2)
+ return drvDir + '\\' + path.substring (2, path.length());
else
return drvDir;
}
*
* @since 1.2
*/
- public File getAbsoluteFile ()
+ public File getAbsoluteFile()
{
return new File (getAbsolutePath());
}
*
* @exception IOException If an error occurs
*/
- public native String getCanonicalPath () throws IOException;
+ public native String getCanonicalPath() throws IOException;
/**
* This method returns a <code>File</code> object representing the
*
* @since 1.2
*/
- public File getCanonicalFile () throws IOException
+ public File getCanonicalFile() throws IOException
{
return new File (getCanonicalPath());
}
*
* @return The file name
*/
- public String getName ()
+ public String getName()
{
int nameSeqIndex = 0;
- if (separatorChar == '\\' && path.length () > 1)
+ if (separatorChar == '\\' && path.length() > 1)
{
// On Windows, ignore the drive specifier or the leading '\\'
// of a UNC network path, if any (a.k.a. the "prefix").
|| (path.charAt (0) >= 'A' && path.charAt (0) <= 'Z'))
&& path.charAt (1) == ':'))
{
- if (path.length () > 2)
+ if (path.length() > 2)
nameSeqIndex = 2;
else
return "";
*
* @return The parent directory of this file
*/
- public String getParent ()
+ public String getParent()
{
String prefix = null;
int nameSeqIndex = 0;
prefix = "/";
nameSeqIndex = 1;
}
- else if (separatorChar == '\\' && path.length () > 1)
+ else if (separatorChar == '\\' && path.length() > 1)
{
if ((path.charAt (0) == '\\' && path.charAt (1) == '\\')
|| (((path.charAt (0) >= 'a' && path.charAt (0) <= 'z')
// 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 ())
+ if (nameSeqIndex < path.length())
{
- String nameSeq = path.substring (nameSeqIndex, path.length ());
+ String nameSeq = path.substring (nameSeqIndex, path.length());
int last = nameSeq.lastIndexOf (separatorChar);
if (last == -1)
return prefix;
- else if (last == (nameSeq.length () - 1))
+ else if (last == (nameSeq.length() - 1))
// Note: The path would not have a trailing separator
// except for cases like "C:\" on Windows (see
// normalizePath( )), where Sun's JRE 1.4 returns null.
*
* @since 1.2
*/
- public File getParentFile ()
+ public File getParentFile()
{
- String parent = getParent ();
- return (parent == null ? null : new File (parent));
+ String parent = getParent();
+ return parent != null ? new File (parent) : null;
}
/**
*
* @return The pathname of this file
*/
- public String getPath ()
+ public String getPath()
{
return path;
}
*
* @return The hash code for this object
*/
- public int hashCode ()
+ public int hashCode()
{
if (caseSensitive)
- return (path.hashCode() ^ 1234321);
+ return path.hashCode() ^ 1234321;
else
- return (path.toLowerCase().hashCode() ^ 1234321);
+ return path.toLowerCase().hashCode() ^ 1234321;
}
/**
* @return <code>true</code> if this object represents an absolute
* file name, <code>false</code> otherwise.
*/
- public native boolean isAbsolute ();
+ public native boolean isAbsolute();
/**
* This method tests whether or not the file represented by this object
*
* @exception SecurityException If reading of the file is not permitted
*/
- public boolean isDirectory ()
+ public boolean isDirectory()
{
- checkRead ();
+ checkRead();
return _stat (DIRECTORY);
}
*
* @exception SecurityException If reading of the file is not permitted
*/
- public boolean isFile ()
+ public boolean isFile()
{
- checkRead ();
+ checkRead();
return _stat (ISFILE);
}
*
* @since 1.2
*/
- public boolean isHidden ()
+ public boolean isHidden()
{
- checkRead ();
+ checkRead();
return _stat (ISHIDDEN);
}
*
* @exception SecurityException If reading of the file is not permitted
*/
- public long lastModified ()
+ public long lastModified()
{
- checkRead ();
+ checkRead();
return attr (MODIFIED);
}
*
* @exception SecurityException If reading of the file is not permitted
*/
- public long length ()
+ public long length()
{
- checkRead ();
+ checkRead();
return attr (LENGTH);
}
*/
public String[] list (FilenameFilter filter)
{
- checkRead ();
+ checkRead();
return (String[]) performList (filter, null, String.class);
}
* @exception SecurityException If read access is not allowed to the
* directory by the <code>SecurityManager</code>
*/
- public String[] list ()
+ public String[] list()
{
- checkRead ();
+ checkRead();
return (String[]) performList (null, null, String.class);
}
*
* @since 1.2
*/
- public File[] listFiles ()
+ public File[] listFiles()
{
- checkRead ();
+ checkRead();
return (File[]) performList (null, null, File.class);
}
*/
public File[] listFiles (FilenameFilter filter)
{
- checkRead ();
+ checkRead();
return (File[]) performList (filter, null, File.class);
}
*/
public File[] listFiles (FileFilter filter)
{
- checkRead ();
+ checkRead();
return (File[]) performList (null, filter, File.class);
}
*
* @return A <code>String</code> representation of this file
*/
- public String toString ()
+ public String toString()
{
return path;
}
* @exception MalformedURLException If the URL cannot be created
* successfully.
*/
- public URL toURL () throws MalformedURLException
+ public URL toURL() throws MalformedURLException
{
// On Win32, Sun's JDK returns URLs of the form "file:/c:/foo/bar.txt",
// while on UNIX, it returns URLs of the form "file:/foo/bar.txt".
if (separatorChar == '\\')
- return new URL ("file:/" + getAbsolutePath ().replace ('\\', '/')
+ return new URL ("file:/" + getAbsolutePath().replace ('\\', '/')
+ (isDirectory() ? "/" : ""));
else
- return new URL ("file:" + getAbsolutePath ()
+ return new URL ("file:" + getAbsolutePath()
+ (isDirectory() ? "/" : ""));
}
/*
* This native method actually creates the directory
*/
- private final native boolean performMkdir ();
+ private final native boolean performMkdir();
/**
* This method creates a directory for the path represented by this object.
*
* @exception SecurityException If write access is not allowed to this file
*/
- public boolean mkdir ()
+ public boolean mkdir()
{
- checkWrite ();
- return performMkdir ();
+ checkWrite();
+ return performMkdir();
}
private static boolean mkdirs (File x)
*
* @exception SecurityException If write access is not allowed to this file
*/
- public boolean mkdirs ()
+ public boolean mkdirs()
{
- checkWrite ();
- if (isDirectory ())
+ checkWrite();
+ if (isDirectory())
return false;
return mkdirs (new File (path));
}
- private static synchronized String nextValue ()
+ private static synchronized String nextValue()
{
return Long.toString(counter++, Character.MAX_RADIX);
}
throw new IOException ("Cannot determine system temporary directory");
directory = new File (dirname);
- if (!directory.exists ())
+ if (!directory.exists())
throw new IOException ("System temporary directory "
- + directory.getName () + " does not exist.");
- if (!directory.isDirectory ())
+ + directory.getName() + " does not exist.");
+ if (!directory.isDirectory())
throw new IOException ("System temporary directory "
- + directory.getName ()
+ + directory.getName()
+ " is not really a directory.");
}
// Now process the prefix and suffix.
- if (prefix.length () < 3)
+ if (prefix.length() < 3)
throw new IllegalArgumentException ("Prefix too short: " + prefix);
if (suffix == null)
// Truncation rules.
// `6' is the number of characters we generate.
- if (prefix.length () + 6 + suffix.length () > maxPathLen)
+ if (prefix.length() + 6 + suffix.length() > maxPathLen)
{
int suf_len = 0;
if (suffix.charAt(0) == '.')
suf_len = 4;
suffix = suffix.substring(0, suf_len);
- if (prefix.length () + 6 + suf_len > maxPathLen)
+ if (prefix.length() + 6 + suf_len > maxPathLen)
prefix = prefix.substring(0, maxPathLen - 6 - suf_len);
}
for (int i = 0; i < 100; ++i)
{
// This is ugly.
- String t = "ZZZZZZ" + nextValue ();
+ String t = "ZZZZZZ" + nextValue();
String l = prefix + t.substring(t.length() - 6) + suffix;
try
{
*
* @since 1.2
*/
- public boolean setReadOnly ()
+ public boolean setReadOnly()
{
- checkWrite ();
+ checkWrite();
return performSetReadOnly();
}
*
* @since 1.2
*/
- public static File[] listRoots ()
+ public static File[] listRoots()
{
File[] roots = performListRoots();
if (time < 0)
throw new IllegalArgumentException("Negative modification time: " + time);
- checkWrite ();
+ checkWrite();
return performSetLastModified(time);
}
- private void checkWrite ()
+ private void checkWrite()
{
// Check the SecurityManager
- SecurityManager s = System.getSecurityManager ();
+ SecurityManager s = System.getSecurityManager();
if (s != null)
s.checkWrite (path);
}
- private void checkRead ()
+ private void checkRead()
{
// Check the SecurityManager
- SecurityManager s = System.getSecurityManager ();
+ SecurityManager s = System.getSecurityManager();
if (s != null)
s.checkRead (path);
* @since 1.2
*/
// FIXME: This should use the ShutdownHook API once we implement that.
- public void deleteOnExit ()
+ public void deleteOnExit()
{
// Check the SecurityManager
- SecurityManager sm = System.getSecurityManager ();
+ SecurityManager sm = System.getSecurityManager();
if (sm != null)
- sm.checkDelete (getName ());
+ sm.checkDelete (getName());
FileDeleter.add (this);
}
private void writeObject (ObjectOutputStream oos) throws IOException
{
- oos.defaultWriteObject ();
+ oos.defaultWriteObject();
oos.writeChar (separatorChar);
}
private void readObject (ObjectInputStream ois)
throws ClassNotFoundException, IOException
{
- ois.defaultReadObject ();
+ ois.defaultReadObject();
// 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 ();
+ char oldSeparatorChar = ois.readChar();
if (oldSeparatorChar != separatorChar)
path = path.replace (oldSeparatorChar, separatorChar);
}
+
} // class File