/[classpath]/classpath/java/io/File.java
ViewVC logotype

Diff of /classpath/java/io/File.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.23 by arenn, Mon Mar 3 00:31:13 2003 UTC revision 1.24 by mkoch, Sun Mar 23 10:53:30 2003 UTC
# Line 46  import gnu.classpath.Configuration; Line 46  import gnu.classpath.Configuration;
46  import gnu.java.io.PlatformHelper;  import gnu.java.io.PlatformHelper;
47    
48  /**  /**
49    * This class represents a file or directory on a local disk.  It provides   * This class represents a file or directory on a local disk.  It provides
50    * facilities for dealing with a variety of systems that use various   * facilities for dealing with a variety of systems that use various
51    * types of path separators ("/" versus "\", for example).  It also   * types of path separators ("/" versus "\", for example).  It also
52    * contains method useful for creating and deleting files and directories.   * contains method useful for creating and deleting files and directories.
53    *   *
54    * @author Aaron M. Renn (arenn@urbanophile.com)   * @author Aaron M. Renn (arenn@urbanophile.com)
55    */   */
56  public class File implements Serializable, Comparable  public class File implements Serializable, Comparable
57  {  {
58    static final long serialVersionUID = 301077366599181567L;    static final long serialVersionUID = 301077366599181567L;
# Line 101  public class File implements Serializabl Line 101  public class File implements Serializabl
101          }          }
102      }      }
103            
   /*************************************************************************/  
   
   /*  
    * Instance Variables  
    */  
   
104    /**    /**
105      * This is the path to the file set when the object is created.  It     * This is the path to the file set when the object is created.  It
106      * may be an absolute or relative path name.     * may be an absolute or relative path name.
     */  
   private String path;  
   
   /*************************************************************************/  
   
   /*  
    * Class Methods  
107     */     */
108      private String path;
109    
110    /**    /**
111      * This method creates a temporary file in the system temporary directory.     * This method creates a temporary file in the system temporary directory.
112      * The files created are guaranteed not to currently exist and the same file     * The files created are guaranteed not to currently exist and the same file
113      * name will never be used twice in the same virtual machine instance.  The     * name will never be used twice in the same virtual machine instance.  The
114      * system temporary directory is determined by examinging the     * system temporary directory is determined by examinging the
115      * <code>java.io.tmpdir</code> system property.     * <code>java.io.tmpdir</code> system property.
116      * <p>     * <p>
117      * The <code>prefix</code> parameter is a sequence of at least three     * The <code>prefix</code> parameter is a sequence of at least three
118      * characters that are used as the start of the generated filename.  The     * characters that are used as the start of the generated filename.  The
119      * <code>suffix</code> parameter is a sequence of characters that is used     * <code>suffix</code> parameter is a sequence of characters that is used
120      * to terminate the file name.  This parameter may be <code>null</code>     * to terminate the file name.  This parameter may be <code>null</code>
121      * and if it is, the suffix defaults to ".tmp".     * and if it is, the suffix defaults to ".tmp".
122      * <p>     * <p>
123      * If a <code>SecurityManager</code> exists, then its <code>checkWrite</code>     * If a <code>SecurityManager</code> exists, then its <code>checkWrite</code>
124      * method is used to verify that this operation is permitted.     * method is used to verify that this operation is permitted.
125      * <p>     * <p>
126      * This method is identical to calling     * This method is identical to calling
127      * <code>createTempFile(prefix, suffix, null)</code>.     * <code>createTempFile(prefix, suffix, null)</code>.
128      *     *
129      * @param prefix The character prefix to use in generating the path name.     * @param prefix The character prefix to use in generating the path name.
130      * @param suffix The character suffix to use in generating the path name.     * @param suffix The character suffix to use in generating the path name.
131      *     *
132      * @exception IllegalArgumentException If the prefix or suffix are not valid.     * @exception IllegalArgumentException If the prefix or suffix are not valid.
133      * @exception SecurityException If there is no permission to perform     * @exception SecurityException If there is no permission to perform
134      * this operation     * this operation
135      * @exception IOException If an error occurs     * @exception IOException If an error occurs
136      */     */
137    public static File createTempFile(String prefix, String suffix)    public static File createTempFile(String prefix, String suffix)
138       throws IllegalArgumentException, SecurityException, IOException       throws IllegalArgumentException, SecurityException, IOException
139    {    {
140      return(createTempFile(prefix, suffix, null));      return(createTempFile(prefix, suffix, null));
141    }    }
142    
   /*************************************************************************/  
   
143    /**    /**
144      * This method creates a temporary file in the specified directory.  If     * This method creates a temporary file in the specified directory.  If
145      * the directory name is null, then this method uses the system temporary     * the directory name is null, then this method uses the system temporary
146      * directory. The files created are guaranteed not to currently exist and     * directory. The files created are guaranteed not to currently exist and
147      * the same file name will never be used twice in the same virtual     * the same file name will never be used twice in the same virtual
148      * machine instance.       * machine instance.  
149      * The system temporary directory is determined by examinging the     * The system temporary directory is determined by examinging the
150      * <code>java.io.tmpdir</code> system property.     * <code>java.io.tmpdir</code> system property.
151      * <p>     * <p>
152      * The <code>prefix</code> parameter is a sequence of at least three     * The <code>prefix</code> parameter is a sequence of at least three
153      * characters that are used as the start of the generated filename.  The     * characters that are used as the start of the generated filename.  The
154      * <code>suffix</code> parameter is a sequence of characters that is used     * <code>suffix</code> parameter is a sequence of characters that is used
155      * to terminate the file name.  This parameter may be <code>null</code>     * to terminate the file name.  This parameter may be <code>null</code>
156      * and if it is, the suffix defaults to ".tmp".     * and if it is, the suffix defaults to ".tmp".
157      * <p>     * <p>
158      * If a <code>SecurityManager</code> exists, then its <code>checkWrite</code>     * If a <code>SecurityManager</code> exists, then its <code>checkWrite</code>
159      * method is used to verify that this operation is permitted.     * method is used to verify that this operation is permitted.
160      *     *
161      * @param prefix The character prefix to use in generating the path name.     * @param prefix The character prefix to use in generating the path name.
162      * @param suffix The character suffix to use in generating the path name.     * @param suffix The character suffix to use in generating the path name.
163      * @param directory The directory to create the file in, or     * @param directory The directory to create the file in, or
164      * <code>null</code> for the default temporary directory     * <code>null</code> for the default temporary directory
165      *     *
166      * @exception IllegalArgumentException If the patterns is not valid     * @exception IllegalArgumentException If the patterns is not valid
167      * @exception SecurityException If there is no permission to perform     * @exception SecurityException If there is no permission to perform
168      * this operation     * this operation
169      * @exception IOException If an error occurs     * @exception IOException If an error occurs
170      */     */
171    public static synchronized File createTempFile(String prefix,    public static synchronized File createTempFile(String prefix,
172                                                   String suffix, File directory)                                                   String suffix, File directory)
173      throws IllegalArgumentException, SecurityException, IOException      throws IllegalArgumentException, SecurityException, IOException
# Line 233  public class File implements Serializabl Line 219  public class File implements Serializabl
219      return(f);      return(f);
220    }    }
221    
   /*************************************************************************/  
   
222    /**    /**
223      * This method is used to create a temporary file     * This method is used to create a temporary file
224      */     */
225    private static native boolean createInternal(String name) throws IOException;    private static native boolean createInternal(String name) throws IOException;
226    
   /*************************************************************************/  
   
227    /**    /**
228      * This method returns an array of filesystem roots.  Some operating systems     * This method returns an array of filesystem roots.  Some operating systems
229      * have volume oriented filesystem.  This method provides a mechanism for     * have volume oriented filesystem.  This method provides a mechanism for
230      * determining which volumes exist.  GNU systems use a single hierarchical     * determining which volumes exist.  GNU systems use a single hierarchical
231      * filesystem, so will have only one "/" filesystem root.     * filesystem, so will have only one "/" filesystem root.
232      *     *
233      * @return An array of <code>File</code> objects for each filesystem root     * @return An array of <code>File</code> objects for each filesystem root
234      * available.     * available.
235      */     */
236    public static File[] listRoots()    public static File[] listRoots()
237    {    {
238      File[] f = new File[1];      File[] f = new File[1];
# Line 259  public class File implements Serializabl Line 241  public class File implements Serializabl
241      return(f);      return(f);
242    }    }
243    
   /*************************************************************************/  
   
   /*  
    * Constructors  
    */  
   
244    /**    /**
245      * This method initializes a new <code>File</code> object to represent     * This method initializes a new <code>File</code> object to represent
246      * a file in the specified directory.  If the <code>directory</code>     * a file in the specified directory.  If the <code>directory</code>
247      * argument is <code>null</code>, the file is assumed to be in the     * argument is <code>null</code>, the file is assumed to be in the
248      * current directory as specified by the <code>user.dir</code> system     * current directory as specified by the <code>user.dir</code> system
249      * property     * property
250      *     *
251      * @param directory The directory this file resides in     * @param directory The directory this file resides in
252      * @param name The name of the file     * @param name The name of the file
253      */     */
254    public File(File directory, String name)    public File(File directory, String name)
255    {    {
256      if (directory == null)      if (directory == null)
# Line 294  public class File implements Serializabl Line 270  public class File implements Serializabl
270        path = dirpath + separator + name;        path = dirpath + separator + name;
271    }    }
272    
   /*************************************************************************/  
   
273    /**    /**
274      * This method initializes a new <code>File</code> object to represent     * This method initializes a new <code>File</code> object to represent
275      * a file in the specified named directory.  The path name to the file     * a file in the specified named directory.  The path name to the file
276      * will be the directory name plus the separator string plus the file     * will be the directory name plus the separator string plus the file
277      * name.  If the directory path name ends in the separator string, another     * name.  If the directory path name ends in the separator string, another
278      * separator string will still be appended.     * separator string will still be appended.
279      *     *
280      * @param dirname The path to the directory the file resides in     * @param dirname The path to the directory the file resides in
281      * @param name The name of the file     * @param name The name of the file
282      */     */
283    public File(String dirname, String name)    public File(String dirname, String name)
284    {    {
285        this(dirname==null? (File)null: new File(dirname), name);        this(dirname==null? (File)null: new File(dirname), name);
286    }    }
287    
   /*************************************************************************/  
   
288    /**    /**
289      * This method initializes a new <code>File</code> object to represent     * This method initializes a new <code>File</code> object to represent
290      * a file with the specified path.     * a file with the specified path.
291      *     *
292      * @param name The path name of the file     * @param name The path name of the file
293      */     */
294    public File(String name)    public File(String name)
295    {    {
296      path = name;      path = name;
# Line 332  public class File implements Serializabl Line 304  public class File implements Serializabl
304          path = PlatformHelper.removeTailSeparator(path);          path = PlatformHelper.removeTailSeparator(path);
305    }    }
306    
   /*************************************************************************/  
   
   /*  
    * Instance Methods  
    */  
   
307    /**    /**
308      * This method returns the name of the file.  This is everything in the     * This method returns the name of the file.  This is everything in the
309      * complete path of the file after the last instance of the separator     * complete path of the file after the last instance of the separator
310      * string.     * string.
311      *     *
312      * @return The file name     * @return The file name
313      */     */
314    public String getName()    public String getName()
315    {    {
316      int pos = PlatformHelper.lastIndexOfSeparator (path);      int pos = PlatformHelper.lastIndexOfSeparator (path);
# Line 357  public class File implements Serializabl Line 323  public class File implements Serializabl
323      return(path.substring(pos + separator.length()));      return(path.substring(pos + separator.length()));
324    }    }
325    
   /*************************************************************************/  
   
326    /**    /**
327      * Returns the path name that represents this file.  May be a relative     * Returns the path name that represents this file.  May be a relative
328      * or an absolute path name     * or an absolute path name
329      *     *
330      * @return The pathname of this file     * @return The pathname of this file
331      */     */
332    public String getPath()    public String getPath()
333    {    {
334      return(path);      return(path);
335    }    }
336    
   /*************************************************************************/  
   
337    /**    /**
338      * This method returns the path of this file as an absolute path name.     * This method returns the path of this file as an absolute path name.
339      * If the path name is already absolute, then it is returned.  Otherwise     * If the path name is already absolute, then it is returned.  Otherwise
340      * the value returned is the current directory plus the separatory     * the value returned is the current directory plus the separatory
341      * string plus the path of the file.  The current directory is determined     * string plus the path of the file.  The current directory is determined
342      * from the <code>user.dir</code> system property.     * from the <code>user.dir</code> system property.
343      *     *
344      * @return The absolute path of this file     * @return The absolute path of this file
345      */     */
346    public String getAbsolutePath()    public String getAbsolutePath()
347    {    {
348      if (isAbsolute ())      if (isAbsolute ())
# Line 396  public class File implements Serializabl Line 358  public class File implements Serializabl
358      return dir + separator + path;      return dir + separator + path;
359    }    }
360    
   /*************************************************************************/  
   
361    /**    /**
362      * This method returns a <code>File</code> object representing the     * This method returns a <code>File</code> object representing the
363      * absolute path of this object.     * absolute path of this object.
364      *     *
365      * @return A <code>File</code> with the absolute path of the object.     * @return A <code>File</code> with the absolute path of the object.
366      */     */
367    public File getAbsoluteFile()    public File getAbsoluteFile()
368    {    {
369      return(new File(getAbsolutePath()));      return(new File(getAbsolutePath()));
370    }    }
371    
   /*************************************************************************/  
   
372    /**    /**
373      * This method returns a canonical representation of the pathname of     * This method returns a canonical representation of the pathname of
374      * this file.  The actual form of the canonical representation is     * this file.  The actual form of the canonical representation is
375      * different.  On the GNU system, the canonical form differs from the     * different.  On the GNU system, the canonical form differs from the
376      * absolute form in that all relative file references to "." and ".."     * absolute form in that all relative file references to "." and ".."
377      * are resolved and removed.     * are resolved and removed.
378      * <p>     * <p>
379      * Note that this method, unlike the other methods which return path     * Note that this method, unlike the other methods which return path
380      * names, can throw an IOException.  This is because native method     * names, can throw an IOException.  This is because native method
381      * might be required in order to resolve the canonical path     * might be required in order to resolve the canonical path
382      *     *
383      * @exception IOException If an error occurs     * @exception IOException If an error occurs
384      */     */
385    public String getCanonicalPath() throws IOException    public String getCanonicalPath() throws IOException
386    {    {
387      String abspath = getAbsolutePath();      String abspath = getAbsolutePath();
388      return PlatformHelper.toCanonicalForm(abspath);      return PlatformHelper.toCanonicalForm(abspath);
389    }    }
390    
   /*************************************************************************/  
   
391    /**    /**
392      * This method returns a <code>File</code> object representing the     * This method returns a <code>File</code> object representing the
393      * canonical path of this object.     * canonical path of this object.
394      *     *
395      * @return A <code>File</code> instance representing the canonical path of     * @return A <code>File</code> instance representing the canonical path of
396      * this object.     * this object.
397      *     *
398      * @exception IOException If an error occurs.     * @exception IOException If an error occurs.
399      */     */
400    public File getCanonicalFile() throws IOException    public File getCanonicalFile() throws IOException
401    {    {
402      return(new File(getCanonicalPath()));      return(new File(getCanonicalPath()));
403    }    }
404    
   /*************************************************************************/  
   
405    /**    /**
406      * This method returns a <code>String</code> the represents this file's     * This method returns a <code>String</code> the represents this file's
407      * parent.  <code>null</code> is returned if the file has no parent.  The     * parent.  <code>null</code> is returned if the file has no parent.  The
408      * parent is determined via a simple operation which removes the     * parent is determined via a simple operation which removes the
409      *     *
410      * @return The parent directory of this file     * @return The parent directory of this file
411      */     */
412    public String getParent()    public String getParent()
413    {    {
414      if (PlatformHelper.isRootDirectory(path))      if (PlatformHelper.isRootDirectory(path))
# Line 469  public class File implements Serializabl Line 423  public class File implements Serializabl
423      return(par_path.substring(0, pos));      return(par_path.substring(0, pos));
424    }    }
425    
   /*************************************************************************/  
   
426    /**    /**
427      * This method returns a <code>File</code> object representing the parent     * This method returns a <code>File</code> object representing the parent
428      * file of this one.     * file of this one.
429      *     *
430      * @param A <code>File</code> for the parent of this object.       * @param A <code>File</code> for the parent of this object.  
431      * <code>null</code>     * <code>null</code>
432      * will be returned if this object does not have a parent.     * will be returned if this object does not have a parent.
433      */     */
434    public File getParentFile()    public File getParentFile()
435    {    {
436      String parent = getParent();      String parent = getParent();
# Line 488  public class File implements Serializabl Line 440  public class File implements Serializabl
440      return(new File(parent));      return(new File(parent));
441    }    }
442    
   /*************************************************************************/  
   
443    /**    /**
444      * This method returns true if this object represents an absolute file     * This method returns true if this object represents an absolute file
445      * path and false if it does not.  The definition of an absolute path varies     * path and false if it does not.  The definition of an absolute path varies
446      * by system.  As an example, on GNU systems, a path is absolute if it starts     * by system.  As an example, on GNU systems, a path is absolute if it starts
447      * with a "/".     * with a "/".
448      *     *
449      * @return <code>true</code> if this object represents an absolute     * @return <code>true</code> if this object represents an absolute
450      * file name, <code>false</code> otherwise.     * file name, <code>false</code> otherwise.
451      */     */
452    public boolean isAbsolute()    public boolean isAbsolute()
453    {    {
454      if (PlatformHelper.beginWithRootPathPrefix (path) > 0)      if (PlatformHelper.beginWithRootPathPrefix (path) > 0)
# Line 507  public class File implements Serializabl Line 457  public class File implements Serializabl
457        return(false);        return(false);
458    }    }
459    
   /*************************************************************************/  
   
460    /**    /**
461      * This method tests whether or not the current thread is allowed to     * This method tests whether or not the current thread is allowed to
462      * to read the file pointed to by this object.  This will be true if and     * to read the file pointed to by this object.  This will be true if and
463      * and only if 1) the file exists and 2) the <code>SecurityManager</code>     * and only if 1) the file exists and 2) the <code>SecurityManager</code>
464      * (if any) allows access to the file via it's <code>checkRead</code>     * (if any) allows access to the file via it's <code>checkRead</code>
465      * method 3) the file is readable.     * method 3) the file is readable.
466      *     *
467      * @return <code>true</code> if reading is allowed,     * @return <code>true</code> if reading is allowed,
468      * <code>false</code> otherwise     * <code>false</code> otherwise
469      *     *
470      * @exception SecurityException If the <code>SecurityManager</code>     * @exception SecurityException If the <code>SecurityManager</code>
471      * does not allow access to the file     * does not allow access to the file
472      */     */
473    public boolean canRead() throws SecurityException    public boolean canRead() throws SecurityException
474    {    {
475      // Test for existence. This also does the SecurityManager check      // Test for existence. This also does the SecurityManager check
# Line 531  public class File implements Serializabl Line 479  public class File implements Serializabl
479      return(canReadInternal(path));      return(canReadInternal(path));
480    }    }
481    
   /*************************************************************************/  
   
482    /**    /**
483      * This native method checks file permissions for reading     * This native method checks file permissions for reading
484      */     */
485    private synchronized native boolean canReadInternal(String path);    private synchronized native boolean canReadInternal(String path);
486    
   /*************************************************************************/  
   
487    /**    /**
488      * This method test whether or not the current thread is allowed to     * This method test whether or not the current thread is allowed to
489      * write to this object.  This will be true if and only if 1) The     * write to this object.  This will be true if and only if 1) The
490      * <code>SecurityManager</code> (if any) allows write access to the     * <code>SecurityManager</code> (if any) allows write access to the
491      * file and 2) The file exists and 3) The file is writable.  To determine     * file and 2) The file exists and 3) The file is writable.  To determine
492      * whether or not a non-existent file can be created, check the parent     * whether or not a non-existent file can be created, check the parent
493      * directory for write access.     * directory for write access.
494      *     *
495      * @return <code>true</code> if writing is allowed, <code>false</code>     * @return <code>true</code> if writing is allowed, <code>false</code>
496      * otherwise     * otherwise
497      *     *
498      * @exception SecurityException If the <code>SecurityManager</code>     * @exception SecurityException If the <code>SecurityManager</code>
499      * does not allow access to the file     * does not allow access to the file
500      */     */
501    public boolean canWrite() throws SecurityException    public boolean canWrite() throws SecurityException
502    {    {
503      // We still need to do a SecurityCheck since exists() only checks      // We still need to do a SecurityCheck since exists() only checks
# Line 580  public class File implements Serializabl Line 524  public class File implements Serializabl
524          }          }
525    }    }
526    
   /*************************************************************************/  
   
527    /**    /**
528      * This native method checks file permissions for writing     * This native method checks file permissions for writing
529      */     */
530    private synchronized native boolean canWriteInternal(String path);    private synchronized native boolean canWriteInternal(String path);
531    
   /*************************************************************************/  
   
532    /**    /**
533      * This method sets the file represented by this object to be read only.     * This method sets the file represented by this object to be read only.
534      * A read only file or directory cannot be modified.  Please note that     * A read only file or directory cannot be modified.  Please note that
535      * GNU systems allow read only files to be deleted if the directory it     * GNU systems allow read only files to be deleted if the directory it
536      * is contained in is writable.     * is contained in is writable.
537      *     *
538      * @return <code>true</code> if the operation succeeded, <code>false</code>     * @return <code>true</code> if the operation succeeded, <code>false</code>
539      * otherwise.     * otherwise.
540      *     *
541      * @exception SecurityException If the <code>SecurityManager</code> does     * @exception SecurityException If the <code>SecurityManager</code> does
542      * not allow this operation.     * not allow this operation.
543      */     */
544    public boolean setReadOnly() throws SecurityException    public boolean setReadOnly() throws SecurityException
545    {    {
546      // Test for existence.      // Test for existence.
# Line 616  public class File implements Serializabl Line 556  public class File implements Serializabl
556      return(setReadOnlyInternal(path));      return(setReadOnlyInternal(path));
557    }    }
558    
   /*************************************************************************/  
   
559    /*    /*
560     * This native method sets the permissions to make the file read only.     * This native method sets the permissions to make the file read only.
561     */     */
562    private native boolean setReadOnlyInternal(String path);    private native boolean setReadOnlyInternal(String path);
563    
   /*************************************************************************/  
   
564    /**    /**
565      * This method tests whether or not the file represented by the object     * This method tests whether or not the file represented by the object
566      * actually exists on the filesystem.     * actually exists on the filesystem.
567      *     *
568      * @return <code>true</code> if the file exists, <code>false</code>otherwise.     * @return <code>true</code> if the file exists, <code>false</code>otherwise.
569      *     *
570      * @exception SecurityException If reading of the file is not permitted     * @exception SecurityException If reading of the file is not permitted
571      */     */
572    public boolean exists() throws SecurityException    public boolean exists() throws SecurityException
573    {    {
574      // Check the SecurityManager      // Check the SecurityManager
# Line 643  public class File implements Serializabl Line 579  public class File implements Serializabl
579      return(existsInternal(path));      return(existsInternal(path));
580    }    }
581    
582    /*************************************************************************/    /*
583       * This native method does the actual checking of file existence.
584    /**     */
     * This native method does the actual checking of file existence.  
     */  
585    private native boolean existsInternal(String path);    private native boolean existsInternal(String path);
586    
   /*************************************************************************/  
   
587    /**    /**
588      * This method tests whether or not the file represented by this object     * This method tests whether or not the file represented by this object
589      * is a "plain" file.  A file is a plain file if and only if it 1) Exists,     * is a "plain" file.  A file is a plain file if and only if it 1) Exists,
590      * 2) Is not a directory or other type of special file.     * 2) Is not a directory or other type of special file.
591      *     *
592      * @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>
593      * otherwise     * otherwise
594      *     *
595      * @exception SecurityException If reading of the file is not permitted     * @exception SecurityException If reading of the file is not permitted
596      */     */
597    public boolean isFile() throws SecurityException    public boolean isFile() throws SecurityException
598    {    {
599      // Check the SecurityManager      // Check the SecurityManager
# Line 672  public class File implements Serializabl Line 604  public class File implements Serializabl
604      return(isFileInternal(path));      return(isFileInternal(path));
605    }    }
606    
607    /*************************************************************************/    /*
608       * This native method does the actual check of whether or not a file
609    /**     * is a plain file or not.  It also handles the existence check to
610      * This native method does the actual check of whether or not a file     * eliminate the overhead of a call to exists()
611      * is a plain file or not.  It also handles the existence check to     */
     * eliminate the overhead of a call to exists()  
     */  
612    private native boolean isFileInternal(String path);    private native boolean isFileInternal(String path);
613    
   /*************************************************************************/  
   
614    /**    /**
615      * This method tests whether or not the file represented by this object     * This method tests whether or not the file represented by this object
616      * is a directory.  In order for this method to return <code>true</code>,     * is a directory.  In order for this method to return <code>true</code>,
617      * the file represented by this object must exist and be a directory.     * the file represented by this object must exist and be a directory.
618      *     *
619      * @return <code>true</code> if this file is a directory, <code>false</code>     * @return <code>true</code> if this file is a directory, <code>false</code>
620      * otherwise     * otherwise
621      *     *
622      * @exception SecurityException If reading of the file is not permitted     * @exception SecurityException If reading of the file is not permitted
623      */     */
624    public boolean isDirectory() throws SecurityException    public boolean isDirectory() throws SecurityException
625    {    {
626      // Check the SecurityManager      // Check the SecurityManager
# Line 703  public class File implements Serializabl Line 631  public class File implements Serializabl
631      return(isDirectoryInternal(path));      return(isDirectoryInternal(path));
632    }    }
633    
634    /*************************************************************************/    /*
635       * This method does the actual check of whether or not a file is a
636    /**     * directory or not.  It also handle the existence check to eliminate
637      * This method does the actual check of whether or not a file is a     * the overhead of a call to exists()
638      * directory or not.  It also handle the existence check to eliminate     */
     * the overhead of a call to exists()  
     */  
639    private native boolean isDirectoryInternal(String path);    private native boolean isDirectoryInternal(String path);
640    
   /*************************************************************************/  
   
641    /**    /**
642      * This method tests whether or not this file represents a "hidden" file.     * This method tests whether or not this file represents a "hidden" file.
643      * On GNU systems, a file is hidden if its name begins with a "."     * On GNU systems, a file is hidden if its name begins with a "."
644      * character.  Files with these names are traditionally not shown with     * character.  Files with these names are traditionally not shown with
645      * directory listing tools.     * directory listing tools.
646      *     *
647      * @return <code>true</code> if the file is hidden, <code>false</code>     * @return <code>true</code> if the file is hidden, <code>false</code>
648      * otherwise.     * otherwise.
649      */     */
650    public boolean isHidden()    public boolean isHidden()
651    {    {
652      if (getName().startsWith("."))      if (getName().startsWith("."))
# Line 731  public class File implements Serializabl Line 655  public class File implements Serializabl
655        return(false);        return(false);
656    }    }
657    
   /*************************************************************************/  
   
658    /**    /**
659      * This method returns the length of the file represented by this object,     * This method returns the length of the file represented by this object,
660      * or 0 if the specified file does not exist.     * or 0 if the specified file does not exist.
661      *     *
662      * @return The length of the file     * @return The length of the file
663      *     *
664      * @exception SecurityException If reading of the file is not permitted     * @exception SecurityException If reading of the file is not permitted
665      */     */
666    public long length() throws SecurityException    public long length() throws SecurityException
667    {    {
668      // Check the SecurityManager      // Check the SecurityManager
# Line 751  public class File implements Serializabl Line 673  public class File implements Serializabl
673      return(lengthInternal(path));      return(lengthInternal(path));
674    }    }
675    
676    /*************************************************************************/    /*
677       * This native method actually determines the length of the file and
678    /**     * handles the existence check
679      * This native method actually determines the length of the file and     */
     * handles the existence check  
     */  
680    private native long lengthInternal(String path);    private native long lengthInternal(String path);
681    
   /*************************************************************************/  
   
682    /**    /**
683      * This method returns the last modification time of this file.  The     * This method returns the last modification time of this file.  The
684      * time value returned is an abstract value that should not be interpreted     * time value returned is an abstract value that should not be interpreted
685      * as a specified time value.  It is only useful for comparing to other     * as a specified time value.  It is only useful for comparing to other
686      * such time values returned on the same system.  In that case, the larger     * such time values returned on the same system.  In that case, the larger
687      * value indicates a more recent modification time.     * value indicates a more recent modification time.
688      * <p>     * <p>
689      * If the file does not exist, then a value of 0 is returned.     * If the file does not exist, then a value of 0 is returned.
690      *     *
691      * @return The last modification time of the file     * @return The last modification time of the file
692      *     *
693      * @exception SecurityException If reading of the file is not permitted     * @exception SecurityException If reading of the file is not permitted
694      */     */
695    public long lastModified() throws SecurityException    public long lastModified() throws SecurityException
696    {    {
697      // Check the SecurityManager      // Check the SecurityManager
# Line 784  public class File implements Serializabl Line 702  public class File implements Serializabl
702      return(lastModifiedInternal(path));      return(lastModifiedInternal(path));
703    }    }
704    
705    /*************************************************************************/    /*
706       * This native method does the actual work of getting the last file
707    /**     * modification time.  It also does the existence check to avoid the
708      * This native method does the actual work of getting the last file     * overhead of a call to exists()
709      * modification time.  It also does the existence check to avoid the     */
     * overhead of a call to exists()  
     */  
710    private native long lastModifiedInternal(String path);    private native long lastModifiedInternal(String path);
711    
   /*************************************************************************/  
   
712    /**    /**
713      * This method sets the modification time on the file to the specified     * This method sets the modification time on the file to the specified
714      * value.  This is specified as the number of seconds since midnight     * value.  This is specified as the number of seconds since midnight
715      * on January 1, 1970 GMT.     * on January 1, 1970 GMT.
716      *     *
717      * @param time The desired modification time.     * @param time The desired modification time.
718      *     *
719      * @return <code>true</code> if the operation succeeded, <code>false</code>     * @return <code>true</code> if the operation succeeded, <code>false</code>
720      * otherwise.     * otherwise.
721      *     *
722      * @exception IllegalArgumentException If the specified time is negative.     * @exception IllegalArgumentException If the specified time is negative.
723      * @exception SecurityException If the <code>SecurityManager</code> will     * @exception SecurityException If the <code>SecurityManager</code> will
724      * not allow this operation.     * not allow this operation.
725      */     */
726    public boolean setLastModified(long time)    public boolean setLastModified(long time)
727      throws IllegalArgumentException, SecurityException      throws IllegalArgumentException, SecurityException
728    {    {
# Line 823  public class File implements Serializabl Line 737  public class File implements Serializabl
737      return(setLastModifiedInternal(path, time));      return(setLastModifiedInternal(path, time));
738    }    }
739    
   /*************************************************************************/  
   
740    /*    /*
741     * This method does the actual setting of the modification time.     * This method does the actual setting of the modification time.
742     */     */
743    private native boolean setLastModifiedInternal(String path, long time);    private native boolean setLastModifiedInternal(String path, long time);
744    
   /*************************************************************************/  
   
745    /**    /**
746      * This method creates a new file of zero length with the same name as     * This method creates a new file of zero length with the same name as
747      * the path of this <code>File</code> object if an only if that file     * the path of this <code>File</code> object if an only if that file
748      * does not already exist.     * does not already exist.
749      * <p>     * <p>
750      * A <code>SecurityManager</code>checkWrite</code> check is done prior     * A <code>SecurityManager</code>checkWrite</code> check is done prior
751      * to performing this action.     * to performing this action.
752      *     *
753      * @return <code>true</code> if the file was created, <code>false</code> if     * @return <code>true</code> if the file was created, <code>false</code> if
754      * the file alread existed.     * the file alread existed.
755      *     *
756      * @exception IOException If an I/O error occurs     * @exception IOException If an I/O error occurs
757      * @exception SecurityException If the <code>SecurityManager</code> will     * @exception SecurityException If the <code>SecurityManager</code> will
758      * not allow this operation to be performed.     * not allow this operation to be performed.
759      */     */
760    public boolean createNewFile() throws IOException, SecurityException    public boolean createNewFile() throws IOException, SecurityException
761    {    {
762      SecurityManager sm = System.getSecurityManager();      SecurityManager sm = System.getSecurityManager();
# Line 856  public class File implements Serializabl Line 766  public class File implements Serializabl
766      return(createInternal(getPath()));      return(createInternal(getPath()));
767    }    }
768    
   /*************************************************************************/  
   
769    /**    /**
770      * This method deletes the file represented by this object.  If this file     * This method deletes the file represented by this object.  If this file
771      * is a directory, it must be empty in order for the delete to succeed.     * is a directory, it must be empty in order for the delete to succeed.
772      *     *
773      * @return <code>true</code> if the file was deleted, <code>false</code>     * @return <code>true</code> if the file was deleted, <code>false</code>
774      * otherwise     * otherwise
775      *     *
776      * @exception SecurityException If deleting of the file is not allowed     * @exception SecurityException If deleting of the file is not allowed
777      */     */
778    public synchronized boolean delete() throws SecurityException    public synchronized boolean delete() throws SecurityException
779    {    {
780      // Check the SecurityManager      // Check the SecurityManager
# Line 877  public class File implements Serializabl Line 785  public class File implements Serializabl
785      return(deleteInternal(path));      return(deleteInternal(path));
786    }    }
787    
788    /*************************************************************************/    /*
789       * This native method handles the actual deleting of the file
790    /**     */
     * This native method handles the actual deleting of the file  
     */  
791    private native boolean deleteInternal(String path);    private native boolean deleteInternal(String path);
792    
   /*************************************************************************/  
   
793    /**    /**
794      * Calling this method requests that the file represented by this object     * Calling this method requests that the file represented by this object
795      * be deleted when the virtual machine exits.  Note that this request cannot     * be deleted when the virtual machine exits.  Note that this request cannot
796      * be cancelled.  Also, it will only be carried out if the virtual machine     * be cancelled.  Also, it will only be carried out if the virtual machine
797      * exits normally.     * exits normally.
798      *     *
799      * @exception SecurityException If deleting of the file is not allowed     * @exception SecurityException If deleting of the file is not allowed
800      */     */
801    public void deleteOnExit() throws SecurityException    public void deleteOnExit() throws SecurityException
802    {    {
803      // Check the SecurityManager      // Check the SecurityManager
# Line 909  public class File implements Serializabl Line 813  public class File implements Serializabl
813      return;      return;
814    }    }
815    
   /*************************************************************************/  
   
816    /**    /**
817      * This method creates a directory for the path represented by this object.     * This method creates a directory for the path represented by this object.
818      *     *
819      * @return <code>true</code> if the directory was created,     * @return <code>true</code> if the directory was created,
820      * <code>false</code> otherwise     * <code>false</code> otherwise
821      *     *
822      * @exception SecurityException If write access is not allowed to this file     * @exception SecurityException If write access is not allowed to this file
823      */     */
824    public boolean mkdir() throws SecurityException    public boolean mkdir() throws SecurityException
825    {    {
826      // Check the SecurityManager      // Check the SecurityManager
# Line 932  public class File implements Serializabl Line 834  public class File implements Serializabl
834      return(mkdirInternal(mk_path));      return(mkdirInternal(mk_path));
835    }    }
836    
837    /*************************************************************************/    /*
838       * This native method actually creates the directory
839    /**     */
     * This native method actually creates the directory  
     */  
840    private native boolean mkdirInternal(String path);    private native boolean mkdirInternal(String path);
841    
   /*************************************************************************/  
   
842    /**    /**
843      * This method creates a directory for the path represented by this file.     * This method creates a directory for the path represented by this file.
844      * It will also create any intervening parent directories if necessary.     * It will also create any intervening parent directories if necessary.
845      *     *
846      * @return <code>true</code> if the directory was created,     * @return <code>true</code> if the directory was created,
847      * <code>false</code> otherwise     * <code>false</code> otherwise
848      *     *
849      * @exception SecurityException If write access is not allowed to this file     * @exception SecurityException If write access is not allowed to this file
850      */     */
851    public boolean mkdirs() throws SecurityException    public boolean mkdirs() throws SecurityException
852    {    {
853      String parent = getParent();      String parent = getParent();
# Line 969  public class File implements Serializabl Line 867  public class File implements Serializabl
867      return(mkdir());      return(mkdir());
868    }    }
869    
   /*************************************************************************/  
   
870    /**    /**
871      * This method renames the file represented by this object to the path     * This method renames the file represented by this object to the path
872      * of the file represented by the argument <code>File</code>.     * of the file represented by the argument <code>File</code>.
873      *     *
874      * @param dest The <code>File</code> object representing the target name     * @param dest The <code>File</code> object representing the target name
875      *     *
876      * @return <code>true</code> if the rename succeeds, <code>false</code>     * @return <code>true</code> if the rename succeeds, <code>false</code>
877      * otherwise.     * otherwise.
878      *     *
879      * @exception SecurityException If write access is not allowed to the     * @exception SecurityException If write access is not allowed to the
880      * file by the <code>SecurityMananger</code>.     * file by the <code>SecurityMananger</code>.
881      */     */
882    public synchronized boolean renameTo(File dest) throws SecurityException    public synchronized boolean renameTo(File dest) throws SecurityException
883    {    {
884      // Check the SecurityManager      // Check the SecurityManager
# Line 996  public class File implements Serializabl Line 892  public class File implements Serializabl
892      return(rc);      return(rc);
893    }    }
894    
895    /*************************************************************************/    /*
896       * This native method actually performs the rename.
897    /**     */
     * This native method actually performs the rename.  
     */  
898    private native boolean renameToInternal(String target, String dest);    private native boolean renameToInternal(String target, String dest);
899    
   /*************************************************************************/  
   
900    /**    /**
901      * This method returns a array of <code>String</code>'s representing the     * This method returns a array of <code>String</code>'s representing the
902      * list of files is then directory represented by this object.  If this     * list of files is then directory represented by this object.  If this
903      * object represents a non-directory file or a non-existent file, then     * object represents a non-directory file or a non-existent file, then
904      * <code>null</code> is returned.  The list of files will not contain     * <code>null</code> is returned.  The list of files will not contain
905      * any names such as "." or ".." which indicate the current or parent     * any names such as "." or ".." which indicate the current or parent
906      * directory.  Also, the names are not guaranteed to be sorted.     * directory.  Also, the names are not guaranteed to be sorted.
907      * <p>     * <p>
908      * A <code>SecurityManager</code> check is made prior to reading the     * A <code>SecurityManager</code> check is made prior to reading the
909      * directory.  If read access to the directory is denied, an exception     * directory.  If read access to the directory is denied, an exception
910      * will be thrown.     * will be thrown.
911      *     *
912      * @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
913      * this object does not represent a valid directory.     * this object does not represent a valid directory.
914      *     *
915      * @exception SecurityException If read access is not allowed to the     * @exception SecurityException If read access is not allowed to the
916      * directory by the <code>SecurityManager</code>     * directory by the <code>SecurityManager</code>
917      */     */
918    public String[] list()    public String[] list()
919    {    {
920      return(list(null));      return(list(null));
921    }    }
922    
   /*************************************************************************/  
   
923    /**    /**
924      * This method returns a array of <code>String</code>'s representing the     * This method returns a array of <code>String</code>'s representing the
925      * list of files is then directory represented by this object.  If this     * list of files is then directory represented by this object.  If this
926      * object represents a non-directory file or a non-existent file, then     * object represents a non-directory file or a non-existent file, then
927      * <code>null</code> is returned.  The list of files will not contain     * <code>null</code> is returned.  The list of files will not contain
928      * any names such as "." or ".." which indicate the current or parent     * any names such as "." or ".." which indicate the current or parent
929      * directory.  Also, the names are not guaranteed to be sorted.     * directory.  Also, the names are not guaranteed to be sorted.
930      * <p>     * <p>
931      * In this form of the <code>list()</code> method, a filter is specified     * In this form of the <code>list()</code> method, a filter is specified
932      * that allows the caller to control which files are returned in the     * that allows the caller to control which files are returned in the
933      * list.  The <code>FilenameFilter</code> specified is called for each     * list.  The <code>FilenameFilter</code> specified is called for each
934      * file returned to determine whether or not that file should be included     * file returned to determine whether or not that file should be included
935      * in the list.     * in the list.
936      * <p>     * <p>
937      * A <code>SecurityManager</code> check is made prior to reading the     * A <code>SecurityManager</code> check is made prior to reading the
938      * directory.  If read access to the directory is denied, an exception     * directory.  If read access to the directory is denied, an exception
939      * will be thrown.     * will be thrown.
940      *     *
941      * @param filter An object which will identify files to exclude from     * @param filter An object which will identify files to exclude from
942      * the directory listing.     * the directory listing.
943      *     *
944      * @return An array of files in the directory, or <code>null</code>     * @return An array of files in the directory, or <code>null</code>
945      * if this object does not represent a valid directory.     * if this object does not represent a valid directory.
946      *     *
947      * @exception SecurityException If read access is not allowed to the     * @exception SecurityException If read access is not allowed to the
948      * directory by the <code>SecurityManager</code>     * directory by the <code>SecurityManager</code>
949      */     */
950    public String[] list(FilenameFilter filter)    public String[] list(FilenameFilter filter)
951    {    {
952      // Check the SecurityManager      // Check the SecurityManager
# Line 1096  public class File implements Serializabl Line 986  public class File implements Serializabl
986      return(retfiles);      return(retfiles);
987    }    }
988    
989    /*************************************************************************/    /*
990       * This native function actually produces the list of file in this
991    /**     * directory
992      * This native function actually produces the list of file in this     */
     * directory  
     */  
993    private native String[] listInternal(String dirname);    private native String[] listInternal(String dirname);
994    
   /*************************************************************************/  
   
995    /**    /**
996      * This method returns an array of <code>File</code> objects representing     * This method returns an array of <code>File</code> objects representing
997      * all the files in the directory represented by this object. If this     * all the files in the directory represented by this object. If this
998      * object does not represent a directory, <code>null</code> is returned.     * object does not represent a directory, <code>null</code> is returned.
999      * Each of the returned <code>File</code> object is constructed with this     * Each of the returned <code>File</code> object is constructed with this
1000      * object as its parent.     * object as its parent.
1001      * <p>     * <p>
1002      * A <code>SecurityManager</code> check is made prior to reading the     * A <code>SecurityManager</code> check is made prior to reading the
1003      * directory.  If read access to the directory is denied, an exception     * directory.  If read access to the directory is denied, an exception
1004      * will be thrown.     * will be thrown.
1005      *     *
1006      * @return An array of <code>File</code> objects for this directory.     * @return An array of <code>File</code> objects for this directory.
1007      *     *
1008      * @exception SecurityException If the <code>SecurityManager</code> denies     * @exception SecurityException If the <code>SecurityManager</code> denies
1009      * access to this directory.     * access to this directory.
1010      */     */
1011    public File[] listFiles()    public File[] listFiles()
1012    {    {
1013      return(listFiles((FilenameFilter)null));      return(listFiles((FilenameFilter)null));
1014    }    }
1015    
   /*************************************************************************/  
   
1016    /**    /**
1017      * This method returns an array of <code>File</code> objects representing     * This method returns an array of <code>File</code> objects representing
1018      * all the files in the directory represented by this object. If this     * all the files in the directory represented by this object. If this
1019      * object does not represent a directory, <code>null</code> is returned.     * object does not represent a directory, <code>null</code> is returned.
1020      * Each of the returned <code>File</code> object is constructed with this     * Each of the returned <code>File</code> object is constructed with this
1021      * object as its parent.     * object as its parent.
1022      * <p>     * <p>
1023      * In this form of the <code>listFiles()</code> method, a filter is specified     * In this form of the <code>listFiles()</code> method, a filter is specified
1024      * that allows the caller to control which files are returned in the     * that allows the caller to control which files are returned in the
1025      * list.  The <code>FilenameFilter</code> specified is called for each     * list.  The <code>FilenameFilter</code> specified is called for each
1026      * file returned to determine whether or not that file should be included     * file returned to determine whether or not that file should be included
1027      * in the list.     * in the list.
1028      * <p>     * <p>
1029      * A <code>SecurityManager</code> check is made prior to reading the     * A <code>SecurityManager</code> check is made prior to reading the
1030      * directory.  If read access to the directory is denied, an exception     * directory.  If read access to the directory is denied, an exception
1031      * will be thrown.     * will be thrown.
1032      *     *
1033      * @return An array of <code>File</code> objects for this directory.     * @return An array of <code>File</code> objects for this directory.
1034      *     *
1035      * @exception SecurityException If the <code>SecurityManager</code> denies     * @exception SecurityException If the <code>SecurityManager</code> denies
1036      * access to this directory.     * access to this directory.
1037      */     */
1038    public File[] listFiles(FilenameFilter filter)    public File[] listFiles(FilenameFilter filter)
1039    {    {
1040      String[] filelist = list(filter);      String[] filelist = list(filter);
# Line 1165  public class File implements Serializabl Line 1049  public class File implements Serializabl
1049      return(fobjlist);      return(fobjlist);
1050    }    }
1051    
   /*************************************************************************/  
   
1052    /**    /**
1053      * This method returns an array of <code>File</code> objects representing     * This method returns an array of <code>File</code> objects representing
1054      * all the files in the directory represented by this object. If this     * all the files in the directory represented by this object. If this
1055      * object does not represent a directory, <code>null</code> is returned.     * object does not represent a directory, <code>null</code> is returned.
1056      * Each of the returned <code>File</code> object is constructed with this     * Each of the returned <code>File</code> object is constructed with this
1057      * object as its parent.     * object as its parent.
1058      * <p>     * <p>
1059      * In this form of the <code>listFiles()</code> method, a filter is specified     * In this form of the <code>listFiles()</code> method, a filter is specified
1060      * that allows the caller to control which files are returned in the     * that allows the caller to control which files are returned in the
1061      * list.  The <code>FileFilter</code> specified is called for each     * list.  The <code>FileFilter</code> specified is called for each
1062      * file returned to determine whether or not that file should be included     * file returned to determine whether or not that file should be included
1063      * in the list.     * in the list.
1064      * <p>     * <p>
1065      * A <code>SecurityManager</code> check is made prior to reading the     * A <code>SecurityManager</code> check is made prior to reading the
1066      * directory.  If read access to the directory is denied, an exception     * directory.  If read access to the directory is denied, an exception
1067      * will be thrown.     * will be thrown.
1068      *     *
1069      * @return An array of <code>File</code> objects for this directory.     * @return An array of <code>File</code> objects for this directory.
1070      *     *
1071      * @exception SecurityException If the <code>SecurityManager</code> denies     * @exception SecurityException If the <code>SecurityManager</code> denies
1072      * access to this directory.     * access to this directory.
1073      */     */
1074    public File[] listFiles(FileFilter filter)    public File[] listFiles(FileFilter filter)
1075    {    {
1076      File[] fobjlist = listFiles((FilenameFilter)null);      File[] fobjlist = listFiles((FilenameFilter)null);
# Line 1216  public class File implements Serializabl Line 1098  public class File implements Serializabl
1098      return(final_list);      return(final_list);
1099    }    }
1100    
   /*************************************************************************/  
   
1101    /**    /**
1102      * This method compares the specified <code>Object</code> to this one     * This method compares the specified <code>Object</code> to this one
1103      * to test for equality.  It does this by comparing the canonical path names     * to test for equality.  It does this by comparing the canonical path names
1104      * of the files.  This method is identical to <code>compareTo(File)</code>     * of the files.  This method is identical to <code>compareTo(File)</code>
1105      * except that if the <code>Object</code> passed to it is not a     * except that if the <code>Object</code> passed to it is not a
1106      * <code>File</code>, it throws a <code>ClassCastException</code>     * <code>File</code>, it throws a <code>ClassCastException</code>
1107      * <p>     * <p>
1108      * The canonical paths of the files are determined by calling the     * The canonical paths of the files are determined by calling the
1109      * <code>getCanonicalPath</code> method on each object.     * <code>getCanonicalPath</code> method on each object.
1110      * <p>     * <p>
1111      * This method returns a 0 if the specified <code>Object</code> is equal     * This method returns a 0 if the specified <code>Object</code> is equal
1112      * 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
1113      * a positive value if it is greater than this one.     * a positive value if it is greater than this one.
1114      *     *
1115      * @return An integer as described above     * @return An integer as described above
1116      *     *
1117      * @exception ClassCastException If the passed <code>Object</code> is     * @exception ClassCastException If the passed <code>Object</code> is
1118      * not a <code>File</code>     * not a <code>File</code>
1119      */     */
1120    public int compareTo(Object obj) throws ClassCastException    public int compareTo(Object obj) throws ClassCastException
1121    {    {
1122      return(compareTo((File)obj));      return(compareTo((File)obj));
1123    }    }
1124    
   /*************************************************************************/  
   
1125    /**    /**
1126      * This method compares the specified <code>File</code> to this one     * This method compares the specified <code>File</code> to this one
1127      * to test for equality.  It does this by comparing the canonical path names     * to test for equality.  It does this by comparing the canonical path names
1128      * of the files.     * of the files.
1129      * <p>     * <p>
1130      * The canonical paths of the files are determined by calling the     * The canonical paths of the files are determined by calling the
1131      * <code>getCanonicalPath</code> method on each object.     * <code>getCanonicalPath</code> method on each object.
1132      * <p>     * <p>
1133      * This method returns a 0 if the specified <code>Object</code> is equal     * This method returns a 0 if the specified <code>Object</code> is equal
1134      * 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
1135      * a positive value if it is greater than this one.     * a positive value if it is greater than this one.
1136      *     *
1137      * @return An integer as described above     * @return An integer as described above
1138      */     */
1139    public int compareTo(File file)    public int compareTo(File file)
1140    {    {
1141      String p1, p2;      String p1, p2;
# Line 1279  public class File implements Serializabl Line 1157  public class File implements Serializabl
1157      return(p1.compareTo(p2));      return(p1.compareTo(p2));
1158    }    }
1159    
   /*************************************************************************/  
   
1160    /**    /**
1161      * This method tests two <code>File</code> objects for equality by     * This method tests two <code>File</code> objects for equality by
1162      * comparing the path of the specified <code>File</code> against the path     * comparing the path of the specified <code>File</code> against the path
1163      * of this object.  The two objects are equal if an only if 1) The     * of this object.  The two objects are equal if an only if 1) The
1164      * argument is not null 2) The argument is a <code>File</code> object and     * argument is not null 2) The argument is a <code>File</code> object and
1165      * 3) The path of the <code>File</code>argument is equal to the path     * 3) The path of the <code>File</code>argument is equal to the path
1166      * of this object.     * of this object.
1167      * <p>     * <p>
1168      * The paths of the files are determined by calling the     * The paths of the files are determined by calling the
1169      * <code>getPath()</code>     * <code>getPath()</code>
1170      * method on each object.     * method on each object.
1171      *     *
1172      * @return <code>true</code> if the two objects are equal,     * @return <code>true</code> if the two objects are equal,
1173      * <code>false</code> otherwise.     * <code>false</code> otherwise.
1174      */     */
1175    public boolean equals(Object obj)    public boolean equals(Object obj)
1176    {    {
1177      if (obj == null)      if (obj == null)
# Line 1309  public class File implements Serializabl Line 1185  public class File implements Serializabl
1185      return(f.getPath().equals(getPath()));      return(f.getPath().equals(getPath()));
1186    }    }
1187    
   /*************************************************************************/  
   
1188    /**    /**
1189      * This method returns a hash code representing this file.  It is the     * This method returns a hash code representing this file.  It is the
1190      * hash code of the path of this file (as returned by <code>getPath()</code>)     * hash code of the path of this file (as returned by <code>getPath()</code>)
1191      * exclusived or-ed with the value 1234321.     * exclusived or-ed with the value 1234321.
1192      *     *
1193      * @return The hash code for this object     * @return The hash code for this object
1194      */     */
1195    public int hashCode()    public int hashCode()
1196    {    {
1197      return(getPath().hashCode() ^ 1234321);      return(getPath().hashCode() ^ 1234321);
1198    }    }
1199    
   /*************************************************************************/  
   
1200    /**    /**
1201      * This method returns a <code>String</code> that is the path name of the     * This method returns a <code>String</code> that is the path name of the
1202      * file as returned by <code>getPath</code>.     * file as returned by <code>getPath</code>.
1203      *     *
1204      * @return A <code>String</code> representation of this file     * @return A <code>String</code> representation of this file
1205      */     */
1206    public String toString()    public String toString()
1207    {    {
1208      return(path);      return(path);
1209    }    }
1210    
   /*************************************************************************/  
   
1211    /**    /**
1212      * This method returns a <code>URL</code> with the <code>file:</code>     * This method returns a <code>URL</code> with the <code>file:</code>
1213      * protocol that represents this file.  The exact form of this URL is     * protocol that represents this file.  The exact form of this URL is
1214      * system dependent.     * system dependent.
1215      *     *
1216      * @return A <code>URL</code> for this object.     * @return A <code>URL</code> for this object.
1217      *     *
1218      * @exception MalformedURLException If the URL cannot be created     * @exception MalformedURLException If the URL cannot be created
1219      * successfully.     * successfully.
1220      */     */
1221    public URL toURL() throws MalformedURLException    public URL toURL() throws MalformedURLException
1222    {    {
1223      String abspath = getAbsolutePath();      String abspath = getAbsolutePath();

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26