edu.sdsc.grid.io.irods
Class IRODSFile

java.lang.Object
  extended by edu.sdsc.grid.io.GeneralFile
      extended by edu.sdsc.grid.io.RemoteFile
          extended by edu.sdsc.grid.io.irods.IRODSFile
All Implemented Interfaces:
java.lang.Comparable

public class IRODSFile
extends RemoteFile

An abstract representation of file and directory pathnames on a iRODS server.

Shares many similarities with the java.io.File class: User interfaces and operating systems use system-dependent pathname strings to name files and directories. This class presents an abstract, system-independent view of hierarchical pathnames. An abstract pathname has two components:

Instances of the IRODSFile class are immutable; that is, once created, the abstract pathname represented by a IRODSFile object will never change.

See Also:
File, GeneralFile

Field Summary
static java.lang.String PATH_SEPARATOR
          Standard iRODS path separator character represented as a string for convenience.
static char PATH_SEPARATOR_CHAR
          The iRODS path separator character, '/'.
 
Fields inherited from class edu.sdsc.grid.io.GeneralFile
BUFFER_MAX_SIZE, directory, fileName, fileSystem, pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
IRODSFile(IRODSFile parent, java.lang.String child)
          Creates a new IRODSFile instance from a parent abstract pathname and a child pathname string.
IRODSFile(IRODSFileSystem fileSystem, java.lang.String filePath)
          Creates a new IRODSFile instance by converting the given pathname string into an abstract pathname.
IRODSFile(IRODSFileSystem fileSystem, java.lang.String parent, java.lang.String child)
          Creates a new iRODSFile instance from a parent pathname string and a child pathname string.
IRODSFile(java.net.URI uri)
          Creates a new IRODSFile 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.
 void changePermissions(java.lang.String permission, java.lang.String newUserName, boolean recursive)
          Change the permissions for this IRODSFile.
 void copyFrom(GeneralFile file, boolean forceOverwrite)
          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, 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.
 java.lang.String getCanonicalPath()
          Returns the canonical pathname string of this abstract pathname.
 java.lang.String getDataType()
           
 java.lang.String getPath()
           
 java.lang.String getPathSeparator()
          This abstract method gets the path separator as defined by the subclass.
 char getPathSeparatorChar()
          This abstract method gets the path separator char as defined by the subclass.
 java.lang.String getResource()
           
 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 isFile(boolean update)
          Tests whether the file denoted by this abstract pathname is a 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.
 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(MetaDataCondition[] conditions)
           
 boolean mkdir()
          Creates the directory named by this abstract pathname.
 boolean renameTo(GeneralFile dest)
          Renames the file denoted by this abstract pathname.
 void replicate(java.lang.String newResource)
          Replicates this RemoteFile to a new resource.
protected  void setDirectory(java.lang.String dir)
          Set the directory.
protected  void setFileName(java.lang.String filePath)
          Set the file name.
protected  void setFileSystem(GeneralFileSystem fileSystem)
          Sets the file system used of this GeneralFile object.
 void setResource(java.lang.String resourceName)
          Sets the physical resource this IRODSFile object will be stored on.
 java.lang.String toString()
          Returns a string representation of this file object.
 
Methods inherited from class edu.sdsc.grid.io.GeneralFile
checksum, compareTo, compareTo, copyFrom, copyTo, createTempFile, firstQueryResult, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getFileSystem, getName, getParent, getParentFile, length, listFiles, listRoots, listRoots, mkdirs, modifyMetaData, query, query, query, setLastModified, setReadOnly, toURI, toURL
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PATH_SEPARATOR

public static final java.lang.String PATH_SEPARATOR
Standard iRODS path separator character represented as a string for convenience. This string contains a single character, namely PATH_SEPARATOR_CHAR.

See Also:
Constant Field Values

PATH_SEPARATOR_CHAR

public static final char PATH_SEPARATOR_CHAR
The iRODS path separator character, '/'.

See Also:
Constant Field Values
Constructor Detail

IRODSFile

public IRODSFile(IRODSFileSystem fileSystem,
                 java.lang.String filePath)
Creates a new IRODSFile instance by converting the given pathname string into an abstract pathname.

Parameters:
fileSystem - The connection to the iRODS server
filePath - A pathname string

IRODSFile

public IRODSFile(IRODSFileSystem fileSystem,
                 java.lang.String parent,
                 java.lang.String child)
Creates a new iRODSFile instance from a parent pathname string and a child pathname string.

If parent is null then the new IRODSFile instance is created as if by invoking the single-argument IRODSFile 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 the child pathname string is absolute then it is converted into a relative pathname in a system-dependent way. If parent is the empty string then the new RemoteFile instance 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:
fileSystem - The connection to the iRODS server
parent - The parent pathname string
child - The child pathname string

IRODSFile

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

If parent is null then the new IRODSFile instance is created as if by invoking the single-argument IRODSFile 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 the child pathname string 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 RemoteFile instance 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

IRODSFile

public IRODSFile(java.net.URI uri)
          throws java.io.IOException,
                 java.net.URISyntaxException
Creates a new IRODSFile instance by converting the given file: URI into an abstract pathname.

iRODS URI protocol:
irods:// [ userName [ : password ] @ ] host [ : port ][ / path ]

example:
irods://irods@irods.sdsc.edu:21/pub/testfile.txt

Parameters:
uri - An absolute, hierarchical URI using a supported scheme.
Throws:
java.lang.NullPointerException - if uri is null.
java.lang.IllegalArgumentException - If the preconditions on the parameter do not hold.
java.io.IOException
java.net.URISyntaxException
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

setFileSystem

protected void setFileSystem(GeneralFileSystem fileSystem)
                      throws java.lang.IllegalArgumentException,
                             java.lang.ClassCastException
Sets the file system used of this GeneralFile object. The file system object must be a subclass of the GeneralFileSystem matching this file object. eg. XYZFile requires XYZFileSystem.

Overrides:
setFileSystem in class GeneralFile
Parameters:
fileSystem - The file system to be used.
Throws:
java.lang.IllegalArgumentException - - if the argument is null.
java.lang.ClassCastException - - if the argument is not an object of the approriate subclass.

setFileName

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

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

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.

getPathSeparator

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

Overrides:
getPathSeparator in class GeneralFile

getPathSeparatorChar

public char getPathSeparatorChar()
This abstract method gets the path separator char as defined by the subclass.

Overrides:
getPathSeparatorChar in class GeneralFile

copyTo

public void copyTo(GeneralFile file,
                   boolean forceOverwrite)
            throws java.io.IOException
Copies this file to another file. This object is the source file. The destination file is given as the argument. 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,
                     boolean forceOverwrite)
              throws java.io.IOException
Copies this file to another file. This object is the source file. The destination file is given as the argument. 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.

setResource

public void setResource(java.lang.String resourceName)
                 throws java.io.IOException,
                        java.lang.NullPointerException,
                        java.lang.IllegalArgumentException
Sets the physical resource this IRODSFile object will be stored on.

Parameters:
resource - The name of resource to be used.
Throws:
java.lang.NullPointerException - If resourceName is null.
java.lang.IllegalArgumentException - If resourceName is not a valid resource.
java.io.IOException - If an IOException occurs during the system change.

getResource

public java.lang.String getResource()
                             throws java.io.IOException
Specified by:
getResource in class RemoteFile
Returns:
resource the physical resource where this file is stored. Will not query the server if this abstract pathname is a directory. Returns null if the file is a directory or does not exist.
Throws:
java.io.IOException - If an IOException occurs during the system query.

getDataType

public java.lang.String getDataType()
                             throws java.io.IOException
Returns:
dataType The dataType string of this file. Will not query the server if this abstract pathname is a directory. Returns null if the file does not exist.
Throws:
java.io.IOException - If an IOException occurs during the system query.

replicate

public void replicate(java.lang.String newResource)
               throws java.io.IOException
Description copied from class: RemoteFile
Replicates this RemoteFile to a new resource. Directories/collections will be recursively replicated.

In some remote systems, one can make copies of a data set and store the copies in different locations. But, all these copies are considered to be identifiable by the same identifier. That is, each copy is considered to be equivalent to each other.

When a user reads a replicated data set, the remote system cycles through all the copies of the datset and reads the one that is accessible at that time.

Specified by:
replicate in class RemoteFile
Parameters:
newResource - The storage resource name of the new copy.
Throws:
java.io.IOException - If an IOException occurs.

changePermissions

public void changePermissions(java.lang.String permission,
                              java.lang.String newUserName,
                              boolean recursive)
                       throws java.io.IOException
Change the permissions for this IRODSFile.

Parameters:
permission - "w" - write;"r" - read;"own" or "all" - owner;"n" - null;
newUserName - The permissions are changed for this user,
userMdasDomain - at this Mdas domain.
recursive - Changes this and all subdirectories
Throws:
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.

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. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file.

Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably.

Overrides:
createNewFile in class GeneralFile
Returns:
true if the named file does not exist and was successfully created; false if the named file already exists
Throws:
java.io.IOException - If an I/O error occurred

createTempFile

public static GeneralFile createTempFile(java.lang.String prefix,
                                         java.lang.String suffix,
                                         GeneralFile directory)
                                  throws java.io.IOException,
                                         java.lang.IllegalArgumentException

Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name. If this method returns successfully then it is guaranteed that:

  1. The file denoted by the returned abstract pathname did not exist before this method was invoked, and
  2. Neither this method nor any of its variants will return the same abstract pathname again in the current invocation of the virtual machine.
This method provides only part of a temporary-file facility. To arrange for a file created by this method to be deleted automatically, use the deleteOnExit method.

The prefix argument must be at least three characters long. It is recommended that the prefix be a short, meaningful string such as "hjb" or "mail". The suffix argument may be null, in which case the suffix ".tmp" will be used.

To create the new file, the prefix and the suffix may first be adjusted to fit the limitations of the underlying platform. If the prefix is too long then it will be truncated, but its first three characters will always be preserved. If the suffix is too long then it too will be truncated, but if it begins with a period character ('.') then the period and the first three characters following it will always be preserved. Once these adjustments have been made the name of the new file will be generated by concatenating the prefix, five or more internally-generated characters, and the suffix.

If the directory argument is null then the default temporary-file directory will be used. Since the SRB does not have a standard temporary directory, files will be placed in a temp/ directory in the user's SRB home directory. There are certain difficulties creating a static connection to the SRB. For this static method to connect to the SRB, .Mdas files must be available in the local home directory/.srb. That is the information that will be used when storing the temporary file. This comprimise is necessary to maintain the designs unity with the java.io.File class.

Parameters:
prefix - The prefix string to be used in generating the file's name; must be at least three characters long
suffix - The suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used
directory - The directory in which the file is to be created, or null if the default temporary-file directory is to be used
Returns:
An abstract pathname denoting a newly-created empty file
Throws:
java.lang.IllegalArgumentException - If the prefix argument contains fewer than three characters
java.io.IOException - If a file could not be created

delete

public boolean delete()
Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a directory, then the directory must be empty in order to be deleted.

Overrides:
delete in class GeneralFile
Returns:
true if and only if the file or directory is successfully deleted; false otherwise

deleteOnExit

public void deleteOnExit()
Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates. Deletion will be attempted only for normal termination of the virtual machine, as defined by the Java Language Specification.

Once deletion has been requested, it is not possible to cancel the request. This method should therefore be used with care.

Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably.

Overrides:
deleteOnExit in class GeneralFile

getPath

public java.lang.String getPath()
Overrides:
getPath in class GeneralFile
Returns:
This abstract pathname as a pathname string.

equals

public boolean equals(java.lang.Object obj)
Tests this abstract pathname for equality with the given object. Returns true if and only if the argument is not null and is an abstract pathname that denotes the same file or directory as this abstract pathname.

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

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

hashCode

public int hashCode()
Computes a hash code for this abstract pathname. The hash code of an abstract pathname is equal to the exclusive or of its pathname string and the decimal value 1234321.

Overrides:
hashCode in class java.lang.Object
Returns:
A hash code for this abstract pathname

isAbsolute

public boolean isAbsolute()
Tests whether this abstract pathname is absolute. A pathname is absolute if its prefix is "/".

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. Also known on the SRB as a collection.

A SRB collection is a logical name given to a set of data sets. All data sets stored in SRB/MCAT are stored in some collection. A collection can have sub-collections, and hence provides a hierarchical structure. A collection in SRB/MCAT can be equated to a directory in a Unix file system. But unlike a file system, a collection is not limited to a single device (or partition). A collection is logical but the datsets grouped under a collection can be stored in heterogeneous storage devices. There is one obvious restriction, the name given to a data set in a collection or sub-collection should be unique in that collection.

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. A file is normal if it is not a directory or a container. Any non-directory or other subclass of SRBFile, such as a SRBContainer, file created by a Java application is guaranteed to be a normal file.

In the terminology of SRB, files are known as data sets. A data set is a "stream-of-bytes" entity that can be uniquely identified. For example, a file in HPSS or Unix is a data set, or a LOB stored in a SRB Vault database is a data set. Importantly, note that a data set is not a set of data objects/files. Each data set in SRB is given a unique internal identifier by SRB. A dataset is associated with a collection.

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

isFile

public boolean isFile(boolean update)
Tests whether the file denoted by this abstract pathname is a file. Also known on the SRB as a dataset.

Parameters:
update - If true, send a new query to the SRB to determine if this abstract pathname refers to a file. If false, this method will return a previously stored value. Also queries the SRB if the value is not already stored with this object.
Returns:
true if and only if the file denoted by this abstract pathname exists and is a directory; 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.

list

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

There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.

If this IRODSFile object denotes a file, the directory containing that file will be listed instead.

This method will return all the files in the directory. Listing directories with a large number of files may take a very long time. The more generic IRODSFile.query() method could be used to iterate through the file list piecewise.

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(MetaDataCondition[] conditions)
Overrides:
list in class GeneralFile

mkdir

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

Overrides:
mkdir in class GeneralFile

renameTo

public boolean renameTo(GeneralFile dest)
                 throws java.lang.IllegalArgumentException,
                        java.lang.NullPointerException
Renames the file denoted by this abstract pathname.

Whether or not this method can move a file from one filesystem to another is platform-dependent. The return value should always be checked to make sure that the rename operation was successful.

Overrides:
renameTo in class GeneralFile
Parameters:
dest - The new abstract pathname for the named file
Throws:
java.lang.IllegalArgumentException - If parameter dest is not a GeneralFile.
java.lang.NullPointerException - - If dest is null

toString

public java.lang.String toString()
Returns a string representation of this file object. The string is formated according to the SRB URI model. Note: the user password will not be included in the URI.

Overrides:
toString in class GeneralFile