edu.sdsc.grid.io.local
Class LocalFile

java.lang.Object
  extended by edu.sdsc.grid.io.GeneralFile
      extended by edu.sdsc.grid.io.local.LocalFile
All Implemented Interfaces:
java.lang.Comparable

public class LocalFile
extends GeneralFile

The LocalFile class is a wrapper class for the java.io.File class. Use it as you would a regular File object. The localFile.getFile() method will return a java.io.File object for those situations where a true java.io.File is required.

LocalFile includes dummy methods for the local file's metadata.

See Also:
File, GeneralFile

Field Summary
static java.lang.String pathSeparator
          The system-dependent path-separator character, represented as a string for convenience.
static char pathSeparatorChar
          The system-dependent path-separator character.
static java.lang.String separator
          The system-dependent default name-separator character, represented as a string for convenience.
static char separatorChar
          The system-dependent default name-separator character.
 
Fields inherited from class edu.sdsc.grid.io.GeneralFile
BUFFER_MAX_SIZE, directory, fileName, fileSystem, PATH_SEPARATOR, PATH_SEPARATOR_CHAR
 
Constructor Summary
LocalFile(java.io.File file)
          Creates a new File instance from a file object.
LocalFile(java.io.File file, java.lang.String child)
          Creates a new File instance from a file object.
LocalFile(LocalFile directory, java.lang.String child)
          Creates a new LocalFile instance from a parent abstract pathname and a child pathname string.
LocalFile(java.lang.String filePath)
          Creates a new LocalFile instance by converting the given pathname string into an abstract pathname.
LocalFile(java.lang.String directory, java.lang.String child)
          Creates a new LocalFile instance from a parent pathname string and a child pathname string.
LocalFile(java.net.URI uri)
          Creates a new LocalFile instance by converting the given file: URI into an abstract pathname.
 
Method Summary
 boolean canRead()
          Tests whether the application can read the file denoted by this abstract pathname.
 boolean canWrite()
          Tests whether the application can modify to the file denoted by this abstract pathname.
 int compareTo(GeneralFile pathName)
          Compares two abstract pathnames lexicographically.
 int compareTo(java.lang.Object o)
          Compares this abstract pathname to another object.
 void copyFrom(GeneralFile file)
          Copies this file to another file.
 void copyFrom(GeneralFile file, boolean forceOverwrite)
          Copies this file to another file.
 void copyTo(GeneralFile file)
          Copies this file to another file.
 void copyTo(GeneralFile file, boolean forceOverwrite)
          Copies this file to another file.
 boolean createNewFile()
          Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.
static GeneralFile createTempFile(java.lang.String prefix, java.lang.String suffix)
          Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.
static GeneralFile createTempFile(java.lang.String prefix, java.lang.String suffix, GeneralFile directory)
          Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.
 boolean delete()
          Deletes the file or directory denoted by this abstract pathname.
 void deleteOnExit()
          Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates.
 boolean equals(java.lang.Object obj)
          Tests this abstract pathname for equality with the given object.
 boolean exists()
          Tests whether the file denoted by this abstract pathname exists.
protected  void finalize()
          Finalizes the object by explicitly letting go of each of its internally held values.
 GeneralFile getAbsoluteFile()
          Returns the absolute form of this abstract pathname.
 java.lang.String getAbsolutePath()
          Returns the absolute pathname string of this abstract pathname.
 GeneralFile getCanonicalFile()
          Returns the canonical form of this abstract pathname.
 java.lang.String getCanonicalPath()
          Returns the canonical pathname string of this abstract pathname.
 java.io.File getFile()
          Returns the internal file object.
protected  java.lang.String getHomeDirectory()
          Gets the home directory to be used with this LocalFile object.
 java.util.Properties getMetaData()
          Dummy method for local file metadata.
 java.lang.String getName()
          Returns the name of the file or directory denoted by this abstract pathname.
 java.lang.String getParent()
          Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.
 GeneralFile getParentFile()
          Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.
 java.lang.String getPath()
          Converts this abstract pathname into a pathname string.
 java.lang.String getPathSeparator()
          This method gets the path separator as defined by the local system.
 char getPathSeparatorChar()
          This method gets the path separator char as defined by the local system.
 int hashCode()
          Computes a hash code for this abstract pathname.
 boolean isAbsolute()
          Tests whether this abstract pathname is absolute.
 boolean isDirectory()
          Tests whether the file denoted by this abstract pathname is a directory.
 boolean isFile()
          Tests whether the file denoted by this abstract pathname is a normal file.
 boolean isHidden()
          Tests whether the file named by this abstract pathname is a hidden file.
 long lastModified()
          Returns the time that the file denoted by this abstract pathname was last modified.
 long length()
          Returns the length of the file denoted by this abstract pathname.
 java.lang.String[] list()
          Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.
 java.lang.String[] list(java.io.FilenameFilter filter)
          Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
 GeneralFile[] listFiles()
          Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.
 GeneralFile[] listFiles(java.io.FileFilter filter)
          Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
 GeneralFile[] listFiles(java.io.FilenameFilter filter)
          Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
 java.util.Iterator listIterator()
          Iterates through the directory/collection/container list.
static GeneralFile[] listRoots()
          List the available filesystem roots.
 boolean mkdir()
          Creates the directory named by this abstract pathname.
 boolean mkdirs()
          Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories.
 boolean renameTo(GeneralFile dest)
          Renames the file denoted by this abstract pathname.
protected  void setDirectory(java.lang.String dir)
          Set the directory.
protected  void setFileName(java.lang.String fileName)
          Set the file name.
 boolean setLastModified(long time)
          Sets the last-modified time of the file or directory named by this abstract pathname.
 boolean setReadOnly()
          Marks the file or directory named by this abstract pathname so that only read operations are allowed.
 java.lang.String toString()
          Returns the pathname string of this abstract pathname.
 java.net.URI toURI()
          Constructs a file: URI that represents this abstract pathname.
 java.net.URL toURL()
          Converts this abstract pathname into a file: URL.
 
Methods inherited from class edu.sdsc.grid.io.GeneralFile
checksum, firstQueryResult, getFileSystem, list, listRoots, modifyMetaData, query, query, query, setFileSystem
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

separatorChar

public static final char separatorChar
The system-dependent default name-separator character. This field is initialized to contain the first character of the value of the system property file.separator. On UNIX systems the value of this field is '/'; on Microsoft Windows systems it is '\\'.

See Also:
System.getProperty(java.lang.String)

separator

public static final java.lang.String separator
The system-dependent default name-separator character, represented as a string for convenience. This string contains a single character, namely separatorChar.


pathSeparatorChar

public static final char pathSeparatorChar
The system-dependent path-separator character. This field is initialized to contain the first character of the value of the system property path.separator. This character is used to separate filenames in a sequence of files given as a path list. On UNIX systems, this character is ':'; on Microsoft Windows systems it is ';'.

See Also:
System.getProperty(java.lang.String)

pathSeparator

public static final java.lang.String pathSeparator
The system-dependent path-separator character, represented as a string for convenience. This string contains a single character, namely pathSeparatorChar.

Constructor Detail

LocalFile

public LocalFile(java.lang.String filePath)
Creates a new LocalFile instance by converting the given pathname string into an abstract pathname. If the given string is the empty string, then the result is the empty abstract pathname.

Throws:
java.lang.NullPointerException - - If the pathname argument is null

LocalFile

public LocalFile(java.lang.String directory,
                 java.lang.String child)
Creates a new LocalFile instance from a parent pathname string and a child pathname string.

Throws:
java.lang.NullPointerException - - If child is null

LocalFile

public LocalFile(LocalFile directory,
                 java.lang.String child)
Creates a new LocalFile instance from a parent abstract pathname and a child pathname string.

Throws:
java.lang.NullPointerException - - If child is null

LocalFile

public LocalFile(java.io.File file)
Creates a new File instance from a file object.

Throws:
java.lang.NullPointerException - - If file is null

LocalFile

public LocalFile(java.io.File file,
                 java.lang.String child)
Creates a new File instance from a file object.

Throws:
java.lang.NullPointerException - - If child is null

LocalFile

public LocalFile(java.net.URI uri)
Creates a new LocalFile instance 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.

Throws:
java.lang.NullPointerException - - If uri is null
java.lang.IllegalArgumentException - - If the preconditions on the parameter do not hold
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Finalizes the object by explicitly letting go of each of its internally held values.

Overrides:
finalize in class GeneralFile
Throws:
java.lang.Throwable

listIterator

public java.util.Iterator listIterator()
                                throws java.io.IOException
Iterates through the directory/collection/container list.

Returns:
Iterator
Throws:
java.io.IOException

setDirectory

protected void setDirectory(java.lang.String dir)
Set the directory.

Overrides:
setDirectory in class GeneralFile
Parameters:
dir - The directory path, need not be absolute.

setFileName

protected void setFileName(java.lang.String fileName)
Set the file name.

Overrides:
setFileName in class GeneralFile
Parameters:
fileName - The file name or fileName plus some or all of the directory path.

getFile

public java.io.File getFile()
Returns the internal file object.


getMetaData

public java.util.Properties getMetaData()
Dummy method for local file metadata.


getPathSeparator

public java.lang.String getPathSeparator()
This method gets the path separator as defined by the local system.

Overrides:
getPathSeparator in class GeneralFile

getPathSeparatorChar

public char getPathSeparatorChar()
This method gets the path separator char as defined by the local system.

Overrides:
getPathSeparatorChar in class GeneralFile

getHomeDirectory

protected java.lang.String getHomeDirectory()
Gets the home directory to be used with this LocalFile object.

Returns:
System.getProperty( "user.home" );
Throws:
java.lang.NullPointerException - if fileSystem is null.

copyTo

public void copyTo(GeneralFile file)
            throws java.io.IOException
Copies this file to another file. If the destination file does not exist, a new one will be created. Otherwise the source file will be appended to the destination file. Directories will be copied recursively.

Overrides:
copyTo in class GeneralFile
Parameters:
file - The file to receive the data.
Throws:
java.lang.NullPointerException - If file is null.
java.io.IOException - If an IOException occurs.

copyTo

public void copyTo(GeneralFile file,
                   boolean forceOverwrite)
            throws java.io.IOException
Copies this file to another file. If the destination file does not exist, a new one will be created. Otherwise the source file will be appended to the destination file. Directories will be copied recursively.

Overrides:
copyTo in class GeneralFile
Parameters:
file - The file to receive the data.
Throws:
java.lang.NullPointerException - If file is null.
java.io.IOException - If an IOException occurs.

copyFrom

public void copyFrom(GeneralFile file)
              throws java.io.IOException
Copies this file to another file. If the destination file does not exist, a new one will be created. Otherwise the source file will be appended to the destination file. Directories will be copied recursively.

Overrides:
copyFrom in class GeneralFile
Parameters:
file - The file to receive the data.
Throws:
java.lang.NullPointerException - If file is null.
java.io.IOException - If an IOException occurs.

copyFrom

public void copyFrom(GeneralFile file,
                     boolean forceOverwrite)
              throws java.io.IOException
Copies this file to another file. If the destination file does not exist, a new one will be created. Otherwise the source file will be appended to the destination file. Directories will be copied recursively.

Overrides:
copyFrom in class GeneralFile
Parameters:
file - The file to receive the data.
Throws:
java.lang.NullPointerException - If file is null.
java.io.IOException - If an IOException occurs.

canRead

public boolean canRead()
Tests whether the application can read the file denoted by this abstract pathname.

Overrides:
canRead in class GeneralFile
Returns:
true if and only if the file specified by this abstract pathname exists and can be read; otherwise false.

canWrite

public boolean canWrite()
Tests whether the application can modify to the file denoted by this abstract pathname.

Overrides:
canWrite in class GeneralFile
Returns:
true if and only if the file system actually contains a file denoted by this abstract pathname and the application is allowed to write to the file; otherwise false.

compareTo

public int compareTo(GeneralFile pathName)
Compares two abstract pathnames lexicographically.

Overrides:
compareTo in class GeneralFile
Returns:
Zero if the argument is equal to this abstract pathname, a value less than zero if this abstract pathname is lexicographically less than the argument, or a value greater than zero if this abstract pathname is lexicographically greater than the argument

compareTo

public int compareTo(java.lang.Object o)
Compares this abstract pathname to another object.

Specified by:
compareTo in interface java.lang.Comparable
Overrides:
compareTo in class GeneralFile
Parameters:
o - The Object to be compared to this abstract pathname
Returns:
If the argument is an abstract pathname, returns zero if the argument is equal to this abstract pathname, a value less than zero if this abstract pathname is lexicographically less than the argument, or a value greater than zero if this abstract pathname is lexicographically greater than the argument


createNewFile

public boolean createNewFile()
                      throws java.io.IOException
Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.

Overrides:
createNewFile in class GeneralFile
Throws:
java.io.IOException

createTempFile

public static GeneralFile createTempFile(java.lang.String prefix,
                                         java.lang.String suffix)
                                  throws java.io.IOException
Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.

Throws:
java.io.IOException

createTempFile

public static GeneralFile createTempFile(java.lang.String prefix,
                                         java.lang.String suffix,
                                         GeneralFile directory)
                                  throws java.io.IOException
Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.

Throws:
java.io.IOException

delete

public boolean delete()
Deletes the file or directory denoted by this abstract pathname.

Overrides:
delete in class GeneralFile

deleteOnExit

public void deleteOnExit()
Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates.

Overrides:
deleteOnExit in class GeneralFile

equals

public boolean equals(java.lang.Object obj)
Tests this abstract pathname for equality with the given object.

Overrides:
equals in class GeneralFile
Parameters:
obj - The object to be compared with this abstract pathname
Returns:
true if and only if the objects are the same; false otherwise

exists

public boolean exists()
Tests whether the file denoted by this abstract pathname exists.

Overrides:
exists in class GeneralFile
Returns:
true if and only if the file denoted by this abstract pathname exists; false otherwise

getAbsoluteFile

public GeneralFile getAbsoluteFile()
Returns the absolute form of this abstract pathname.

Overrides:
getAbsoluteFile in class GeneralFile
Returns:
The absolute abstract pathname denoting the same file or directory as this abstract pathname

getAbsolutePath

public java.lang.String getAbsolutePath()
Returns the absolute pathname string of this abstract pathname.

Overrides:
getAbsolutePath in class GeneralFile
Returns:
The absolute pathname denoting the same file or directory as this abstract pathname

getCanonicalFile

public GeneralFile getCanonicalFile()
                             throws java.io.IOException
Returns the canonical form of this abstract pathname.

Overrides:
getCanonicalFile in class GeneralFile
Returns:
The canonical abstract pathname denoting the same file or directory as this abstract pathname
Throws:
java.io.IOException - If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries

getCanonicalPath

public java.lang.String getCanonicalPath()
                                  throws java.io.IOException
Returns the canonical pathname string of this abstract pathname.

Overrides:
getCanonicalPath in class GeneralFile
Returns:
The canonical pathname string denoting the same file or directory as this abstract pathname
Throws:
java.io.IOException - If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries

getName

public java.lang.String getName()
Returns the name of the file or directory denoted by this abstract pathname.

Overrides:
getName in class GeneralFile
Returns:
The name of the file or directory denoted by this abstract pathname.

getParent

public java.lang.String getParent()
Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.

Overrides:
getParent in class GeneralFile
Returns:
The pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.

getParentFile

public GeneralFile getParentFile()
Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.

Overrides:
getParentFile in class GeneralFile
Returns:
The abstract pathname of the parent directory named by this abstract pathname, or null if this pathname does not name a parent

getPath

public java.lang.String getPath()
Converts this abstract pathname into a pathname string.

Overrides:
getPath in class GeneralFile
Returns:
This abstract pathname as a pathname string.

hashCode

public int hashCode()
Computes a hash code for this abstract pathname.

Overrides:
hashCode in class java.lang.Object

isAbsolute

public boolean isAbsolute()
Tests whether this abstract pathname is absolute.

Overrides:
isAbsolute in class GeneralFile
Returns:
true if this abstract pathname is absolute, false otherwise

isDirectory

public boolean isDirectory()
Tests whether the file denoted by this abstract pathname is a directory.

Overrides:
isDirectory in class GeneralFile
Returns:
true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise

isFile

public boolean isFile()
Tests whether the file denoted by this abstract pathname is a normal file.

Overrides:
isFile in class GeneralFile
Returns:
true if and only if the file denoted by this abstract pathname exists and is a normal file; false otherwise

isHidden

public boolean isHidden()
Tests whether the file named by this abstract pathname is a hidden file.

Overrides:
isHidden in class GeneralFile
Returns:
true if and only if the file denoted by this abstract pathname is hidden.

lastModified

public long lastModified()
Returns the time that the file denoted by this abstract pathname was last modified.

Overrides:
lastModified in class GeneralFile
Returns:
A long value representing the time the file was last modified, measured in system-dependent way.

length

public long length()
Returns the length of the file denoted by this abstract pathname.

Overrides:
length in class GeneralFile
Returns:
The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist

list

public java.lang.String[] list()
Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.

Overrides:
list in class GeneralFile
Returns:
An array of strings naming the files and directories in the directory denoted by this abstract pathname.

list

public java.lang.String[] list(java.io.FilenameFilter filter)
Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.


listFiles

public GeneralFile[] listFiles()
Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.

Overrides:
listFiles in class GeneralFile
Returns:
An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty.

listFiles

public GeneralFile[] listFiles(java.io.FileFilter filter)
Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.


listFiles

public GeneralFile[] listFiles(java.io.FilenameFilter filter)
Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.


listRoots

public static GeneralFile[] listRoots()
List the available filesystem roots.


mkdir

public boolean mkdir()
Creates the directory named by this abstract pathname.

Overrides:
mkdir in class GeneralFile

mkdirs

public boolean mkdirs()
Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories.

Overrides:
mkdirs in class GeneralFile

renameTo

public boolean renameTo(GeneralFile dest)
Renames the file denoted by this abstract pathname.

Overrides:
renameTo in class GeneralFile
Parameters:
dest - The new abstract pathname for the named file

setLastModified

public boolean setLastModified(long time)
Sets the last-modified time of the file or directory named by this abstract pathname.

Overrides:
setLastModified in class GeneralFile
Parameters:
time - The new last-modified time, measured in a system-dependent way.

setReadOnly

public boolean setReadOnly()
Marks the file or directory named by this abstract pathname so that only read operations are allowed.

Overrides:
setReadOnly in class GeneralFile

toString

public java.lang.String toString()
Returns the pathname string of this abstract pathname.

Overrides:
toString in class GeneralFile

toURI

public java.net.URI toURI()
Constructs a file: URI that represents this abstract pathname.

Overrides:
toURI in class GeneralFile
Returns:
An absolute, hierarchical URI with a scheme equal to "file", a path representing this abstract pathname, and undefined authority, query, and fragment components
See Also:
GeneralFile.GeneralFile(java.net.URI), URI, URI.toURL()

toURL

public java.net.URL toURL()
                   throws java.net.MalformedURLException
Converts this abstract pathname into a file: URL.

Overrides:
toURL in class GeneralFile
Returns:
A URL object representing the equivalent file URL
Throws:
java.net.MalformedURLException - If the path cannot be parsed as a URL
See Also:
GeneralFile.toURI(), URI, URI.toURL(), URL