tribble.io
Class Filename

java.lang.Object
  extended by java.io.File
      extended by tribble.io.Filename
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<java.io.File>

public class Filename
extends java.io.File

Enhanced abstract pathname (filename).

This class extends the standard java.io.File class, adding some useful methods.

Objects of this class type can be used anywhere that an object of type java.io.File can be used.

Note that Filename objects are immutable, i.e., their contents cannot be modified, in the same way that java.io.File objects are immutable.

Since:
2003-02-21
Version:
$Revision: 1.1 $ $Date: 2003/02/22 04:08:01 $
Author:
David R. Tribble, david@tribble.com.

Copyright 2003 by David R. Tribble, all rights reserved.
Permission is granted to freely use and distribute this source code provided that the original copyright and authorship notices remain intact.

See Also:
Serialized Form

Field Summary
(package private) static java.lang.String REV
          Revision information.
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
Filename(java.io.File path)
          Create a new filename from an abstract pathname.
Filename(java.io.File parent, java.lang.String child)
          Create a new filename from a parent abstract pathname and a child pathname string.
Filename(java.lang.String path)
          Constructor.
Filename(java.lang.String parent, java.lang.String child)
          Create a new filename from a parent abstract pathname and a child pathname string.
Filename(java.net.URI uri)
          Create a new filename by converting the given "file:" URI into an abstract pathname.
 
Method Summary
 java.util.Date getLastModified()
          Retrieve the last modification date of this filename.
 java.lang.String getSuffix()
          Extract the suffix (extension) of this pathname.
static java.lang.String getSuffix(java.io.File path)
          Extract the suffix (extension) of a filename.
 void setLastModified(java.util.Date time)
          Change the last modification date of this filename.
 
Methods inherited from class java.io.File
canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getName, getParent, getParentFile, getPath, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setLastModified, setReadOnly, toString, toURI, toURL
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

REV

static final java.lang.String REV
Revision information.

See Also:
Constant Field Values
Constructor Detail

Filename

public Filename(java.lang.String path)
Constructor. If the given string is empty (""), then the result is an empty abstract pathname.

Parameters:
path - A pathname string.
Throws:
java.lang.NullPointerException - (unchecked) Thrown if path is null.
Since:
1.1, 2003-02-21

Filename

public Filename(java.lang.String parent,
                java.lang.String child)
Create a new filename from a parent abstract pathname and a child pathname string.

If parent is null then the new filename is created as if by invoking the single-argument Filename constructor on the given child pathname string.

Otherwise the parent pathname string is taken to denote a directory, and the child pathname string is taken to denote either a directory or a file. If child is absolute then it is converted into a relative pathname in a system-dependent way. If parent is empty ("") then the new filename is created by converting child into an abstract pathname and resolving the result against a system-dependent default directory. Otherwise each pathname string is converted into an abstract pathname and the child abstract pathname is resolved against the parent.

Parameters:
parent - The parent pathname string.
child - The child pathname string.
Throws:
java.lang.NullPointerException - (unchecked) Thrown if child is null.
Since:
1.1, 2003-02-21

Filename

public Filename(java.io.File parent,
                java.lang.String child)
Create a new filename from a parent abstract pathname and a child pathname string.

If parent is null then the new filename is created as if by invoking the single-argument Filename constructor on the given child pathname string.

Otherwise the parent abstract pathname is taken to denote a directory, and the child pathname string is taken to denote either a directory or a file. If child is absolute then it is converted into a relative pathname in a system-dependent way. If parent is the empty abstract pathname then the new filename is created by converting child into an abstract pathname and resolving the result against a system-dependent default directory. Otherwise each pathname string is converted into an abstract pathname and the child abstract pathname is resolved against the parent.

Parameters:
parent - The parent abstract pathname.
child - The child pathname string.
Throws:
java.lang.NullPointerException - (unchecked) Thrown if child is null.
Since:
1.1, 2003-02-21

Filename

public Filename(java.io.File path)
Create a new filename from an abstract pathname.

Note that this is a convenience method for converting a java.io.File object into a Filename.

Parameters:
path - An abstract pathname.
Since:
1.1, 2003-02-21

Filename

public Filename(java.net.URI uri)
Create a new filename by converting the given "file:" URI into an abstract pathname.

The exact form of a "file:" URI is system-dependent, hence the transformation performed by this constructor is also system-dependent.

For a given abstract pathname f it is guaranteed that

    new Filename(f.toURI()).equals(f) 
is true so long as the original abstract pathname, the URI, and the new abstract pathname are all created in (possibly different invocations of) the same Java virtual machine. This relationship typically does not hold, however, when a "file:" URI that is created in a virtual machine on one operating system is converted into an abstract pathname in a virtual machine on a different operating system.

Parameters:
uri - An absolute, hierarchical URI with a scheme equal to "file", a non-empty path component, and undefined authority, query, and fragment components.
Throws:
java.lang.NullPointerException - (unchecked) Thrown if uri is null .
java.lang.IllegalArgumentException - (unchecked) Thrown if the preconditions on the parameter do not hold.
Since:
1.1, 2003-02-21
Method Detail

getSuffix

public static java.lang.String getSuffix(java.io.File path)
Extract the suffix (extension) of a filename.

Parameters:
path - An abstract pathname.
Returns:
The suffix of the filename. Some example filenames and their suffixes are:
    "foo"               => ""  (empty suffix)
    "foo."              => "."
    "foo.txt"           => ".txt"
    "foo.x.h"           => ".h"
    "/my/files/abc..pl" => ".pl"
 
Since:
1.1, 2003-02-21

getSuffix

public java.lang.String getSuffix()
Extract the suffix (extension) of this pathname.

Returns:
The suffix of the filename. Some example filenames and their suffixes are:
    "foo"               => ""  (empty suffix)
    "foo."              => "."
    "foo.txt"           => ".txt"
    "foo.x.h"           => ".h"
    "/my/files/abc..pl" => ".pl"
 
Since:
1.1, 2003-02-21

getLastModified

public java.util.Date getLastModified()
Retrieve the last modification date of this filename.

Returns:
The date that this named file was last modified.
Since:
1.1, 2003-02-21
See Also:
File.lastModified()

setLastModified

public void setLastModified(java.util.Date time)
Change the last modification date of this filename.

Parameters:
time - A date.
Since:
1.1, 2003-02-21
See Also:
File.setLastModified(long)