edu.sdsc.grid.io.srb
Class SRBFile

java.lang.Object
  extended by edu.sdsc.grid.io.GeneralFile
      extended by edu.sdsc.grid.io.RemoteFile
          extended by edu.sdsc.grid.io.srb.SRBFile
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
SRBContainer

public class SRBFile
extends RemoteFile

An abstract representation of file and directory pathnames on the SRB.

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.

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.

This class 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, SRB view of hierarchical pathnames. An abstract pathname has two components:

  1. An optional SRB prefix string, "/" 
  2. A sequence of zero or more string names.
Each name in an abstract pathname except for the last denotes a directory; the last name may denote either a directory or a file. The empty abstract pathname has no prefix and an empty name sequence.

When an abstract pathname is converted into a pathname string, each name is separated from the next by a single copy of the default separator character.

A pathname in string form may be either absolute or relative. On construction the pathname is made absolute. An absolute pathname is complete in that no other information is required in order to locate the file that it denotes. A relative pathname, in contrast, must be interpreted in terms of information taken from some other pathname. By default the classes in the edu.sdsc.grid.io.srb package always resolve relative pathnames against the user home directory. This directory is named in the .MdasEnv file.

The prefix concept is used to handle root directories on the SRB is the same as for UNIX platforms.

For the SRB, the prefix of an absolute pathname is always "/". Relative pathnames have no prefix. The abstract pathname denoting the root directory has the prefix "/" and an empty name sequence.

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

Since:
JARGON1.0
See Also:
File, GeneralFile, RemoteFile

Field Summary
 boolean completeDirectoryList
          For list() should the entire contents be listed, or just SRBFileSystem.DEFAULT_RECORDS_WANTED in number.
static int FILE_CATALOG
          A SRB catalog type.
static int LDAP_CATALOG
          A SRB catalog type.
static int MDAS_CATALOG
          Default SRB catalog type.
protected  SRBFileSystem srbFileSystem
          Holds the server object used by this srb file.
 
Fields inherited from class edu.sdsc.grid.io.GeneralFile
BUFFER_MAX_SIZE, directory, fileName, fileSystem, PATH_SEPARATOR, PATH_SEPARATOR_CHAR, pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
SRBFile(SRBFile parent, java.lang.String child)
          Creates a new SRBFile instance from a parent abstract pathname and a child pathname string.
SRBFile(SRBFileSystem srbFileSystem, java.lang.String filePath)
          Creates a new SRBFile instance by converting the given pathname string into an abstract pathname.
SRBFile(SRBFileSystem srbFileSystem, java.lang.String parent, java.lang.String child)
          Creates a new SRBFile instance from a parent pathname string and a child pathname string.
SRBFile(java.net.URI uri)
          Creates a new GeneralFile instance by converting the given file: URI into an abstract pathname.
 
Method Summary
 void backup(java.lang.String backupResource)
          Backup a data object.
 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, java.lang.String userMdasDomain)
          Change the permissions for this SRBFile.
 void changePermissions(java.lang.String permission, java.lang.String newUserName, java.lang.String userMdasDomain, boolean recursive)
          Change the permissions for this SRBFile.
 java.lang.String checksum()
          Checksum a SRB data file.
 java.lang.String checksum(boolean force)
          Checksum a SRB data file.
 void copyFrom(GeneralFile file, boolean forceOverwrite)
          Copies this file to another file.
 void copyFrom(GeneralFile file, boolean forceOverwrite, boolean bulkCopy)
          Copies this file to another file.
 void copyTo(GeneralFile file, boolean forceOverwrite)
          Copies this file to another file.
 void copyTo(GeneralFile file, boolean forceOverwrite, boolean bulkCopy)
          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.
 boolean delete(boolean force)
          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.
 java.io.InputStream executeProxyCommand(java.lang.String command, java.lang.String commandArgs)
          Proxy Operation that executes a command.
 boolean exists()
          Tests whether the file denoted by this abstract pathname exists.
 long fileCopyStatus()
          The number of bytes transfered so far by a currently executing SRBFile.copyTo/copyFrom command.
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.
 int getCatalogType()
           
 java.lang.String getDataType()
           
 GeneralFileSystem getFileSystem()
           
 java.lang.String getName()
           
 java.lang.String getPath()
           
 java.lang.String getPathSeparator()
          Deprecated. Use separator and pathSeparator
 char getPathSeparatorChar()
          Deprecated. Use separatorChar and pathSeparatorChar
 java.lang.String getPermissions()
          Get the permissions of the current user for this SRBFile: write, read, all, annotate or null.
 MetaDataRecordList[] getPermissions(boolean allUsers)
          Gets all the non-null permissions of all SRB users for this SRBFile: write, read, all, annotate or null.
 int getReplicaNumber()
          Gets the specific physical data replication refered to by this object.
 java.lang.String getResource()
           
 java.lang.String getServerLocalPath()
          The local filepath of the data when logged on the SRB server.
 long[] getStat()
          Retrieves the platform independent stat structure.
 int hashCode()
          Computes a hash code for this abstract pathname.
 boolean isAbsolute()
          Tests whether this abstract pathname is absolute.
 boolean isContainer()
          Tests whether the file denoted by this abstract pathname is a SRB container.
 boolean isDirectory()
          Tests whether the file denoted by this abstract pathname is a directory.
 boolean isDirectory(boolean update)
          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.
 void link(SRBFile newLink)
          Links newLink with this object as the source.
 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)
          Returns the array of strings naming the files and directories in the directory denoted by this abstract pathname and which match a query formed using these conditions.
 boolean mkdir()
          Creates the directory named by this abstract pathname.
 void modifyMetaData(MetaDataRecordList record)
          Change the values of the metadata associated with this file object.
 MetaDataRecordList[] query(MetaDataCondition[] conditions, MetaDataSelect[] selects)
          Queries the file server to find all files that match a set of conditions.
 MetaDataRecordList[] query(MetaDataCondition[] conditions, MetaDataSelect[] selects, int recordsWanted)
           
 MetaDataRecordList[] query(MetaDataSelect select)
          Queries metadata specific to this SRBFile object and selects one metadata value, select, to be returned.
 MetaDataRecordList[] query(MetaDataSelect[] selects)
          Queries metadata specific to this SRBFile object.
 MetaDataRecordList[] query(MetaDataSelect[] selects, int recordsWanted)
           
 MetaDataRecordList[] query(java.lang.String fieldName)
          Queries metadata specific to this SRBFile object and selects one metadata value, fieldName, to be returned.
 MetaDataRecordList[] query(java.lang.String[] fieldNames)
          Queries metadata specific to this SRBFile object.
 void register(java.lang.String registeringObjectPath, long dataSize)
          Registers the location of a file on a SRB physical resource.
 boolean renameTo(GeneralFile dest)
          Renames the file denoted by this abstract pathname.
 void replicate(java.lang.String newResource)
          Replicates this SRBFile to a new resource.
 void setDataType(java.lang.String dataTypeName)
          Sets the dataType string of this SRBFile.
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 SRB server used of this SRBFile object.
 boolean setLastModified(long time)
          This method will only change the lastModified time to the current time.
 boolean setReadOnly()
          Marks the file or directory named by this abstract pathname so that only read operations are allowed.
 void setReplicaNumber(int replicaNumber)
          Sets the specific physical data replication refered to by this object.
 void setResource(java.lang.String resourceName)
          Sets the physical resource this SRBFile object will be stored on.
 void setServerLocalPath(java.lang.String serverLocalPath)
          The local filepath of the data when logged on the SRB server.
 java.lang.String toString()
          Returns a string representation of this file object.
 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
compareTo, compareTo, copyFrom, copyTo, createTempFile, firstQueryResult, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getParent, getParentFile, length, listFiles, listRoots, listRoots, mkdirs
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MDAS_CATALOG

public static final int MDAS_CATALOG
Default SRB catalog type.

See Also:
Constant Field Values

LDAP_CATALOG

public static final int LDAP_CATALOG
A SRB catalog type.

See Also:
Constant Field Values

FILE_CATALOG

public static final int FILE_CATALOG
A SRB catalog type.

See Also:
Constant Field Values

srbFileSystem

protected SRBFileSystem srbFileSystem
Holds the server object used by this srb file. Same as the fileSystem variable, but cast from GeneralFileSystem to SRBFileSystem.


completeDirectoryList

public boolean completeDirectoryList
For list() should the entire contents be listed, or just SRBFileSystem.DEFAULT_RECORDS_WANTED in number.

Constructor Detail

SRBFile

public SRBFile(SRBFileSystem srbFileSystem,
               java.lang.String filePath)
        throws java.lang.NullPointerException
Creates a new SRBFile instance by converting the given pathname string into an abstract pathname.

Parameters:
fileSystem - The connection to the SRB
filePath - The pathname string
Throws:
java.lang.NullPointerException - If the given string is null or the empty string.

SRBFile

public SRBFile(SRBFileSystem srbFileSystem,
               java.lang.String parent,
               java.lang.String child)
        throws java.lang.NullPointerException,
               java.lang.IllegalArgumentException
Creates a new SRBFile instance from a parent pathname string and a child pathname string.

If parent is null then the new SRBFile instance is created as if by invoking the single-argument SRBFile 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 SRB pathname. If parent is the empty string then the new SRBFile instance is created by converting child into an abstract pathname and resolving the result against the user's SRB default home 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 SRB
parent - The parent pathname string
child - The child pathname string
Throws:
java.lang.NullPointerException - If the child string is null or the empty string.
java.lang.IllegalArgumentException

SRBFile

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

If parent is null then the new SRBFile instance is created as if by invoking the single-argument SRBFile 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 SRB pathname. If parent is the empty abstract pathname then the new SRBFile instance is created by converting child into an abstract pathname and resolving the result against the user's SRB default home 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 - If the child string is null or the empty string.

SRBFile

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

SRB URI protocol:
srb:// [ userName . domainHome [ : password ] @ ] host [ : port ][ / path ]

example:
srb://testuser.sdsc:mypassword@srb.sdsc.edu:5555/home/testuser.sdsc/testfile.txt

Parameters:
uri - An absolute, hierarchical URI using the srb scheme.
Throws:
java.lang.NullPointerException - if uri is null.
java.lang.IllegalArgumentException - If the preconditions on the parameter do not hold.
java.io.IOException - Can occur during the creation of the internal fileSystem object.
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

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.

setFileSystem

protected void setFileSystem(GeneralFileSystem fileSystem)
                      throws java.lang.IllegalArgumentException
Sets the SRB server used of this SRBFile object.

Overrides:
setFileSystem in class GeneralFile
Parameters:
fileSystem - The SRB server to be used.
Throws:
java.lang.IllegalArgumentException - - if the argument is null.
java.lang.ClassCastException - - if the argument is not a SRBFileSystem object.

setResource

public void setResource(java.lang.String resourceName)
                 throws java.io.IOException,
                        java.lang.NullPointerException,
                        java.lang.IllegalArgumentException
Sets the physical resource this SRBFile 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.

setDataType

public void setDataType(java.lang.String dataTypeName)
                 throws java.io.IOException
Sets the dataType string of this SRBFile. If dataTypeName is null, the default type of "generic", will be used.

Throws:
java.io.IOException - If an IOException occurs during the system change.

setReplicaNumber

public void setReplicaNumber(int replicaNumber)
Sets the specific physical data replication refered to by this object. ReplicaNumbers are always positive. setting a negative number will remove the any specific replica reference.


setServerLocalPath

public void setServerLocalPath(java.lang.String serverLocalPath)
The local filepath of the data when logged on the SRB server.

The serverLocalPath points to a filepath on the SRB server (the directory plus filename.) Most files are stored in the SRB Vault, but this file can be stored anywhere on the server that you have permissions. You must have a user account on the SRB server machine, and that account must have read/write permissions to this abstract filepath.


getReplicaNumber

public int getReplicaNumber()
Gets the specific physical data replication refered to by this object.

Returns:
The replica number refered to by this SRBFile object. Returns a negative value if this SRBFile object does not refer to a specific replica.

getResource

public java.lang.String getResource()
                             throws java.io.IOException
Specified by:
getResource in class RemoteFile
Returns:
resource the physical resource where this SRBFile is stored. Will not query the SRB 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 SRBFile. Will not query the SRB 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.

getCatalogType

public int getCatalogType()
Returns:
catalogType the catalog type int of this SRBFile.

getPathSeparator

public final java.lang.String getPathSeparator()
Deprecated. Use separator and pathSeparator

This method gets the path separator as defined by the SRB protocol.

Overrides:
getPathSeparator in class GeneralFile

getPathSeparatorChar

public final char getPathSeparatorChar()
Deprecated. Use separatorChar and pathSeparatorChar

This method gets the path separator char as defined by the SRB protocol.

Overrides:
getPathSeparatorChar in class GeneralFile

getFileSystem

public GeneralFileSystem getFileSystem()
                                throws java.lang.NullPointerException
Overrides:
getFileSystem in class GeneralFile
Returns:
fileSystem the SRBFileSystem object of this SRBFile.
Throws:
java.lang.NullPointerException - if fileSystem is null.

getServerLocalPath

public java.lang.String getServerLocalPath()
The local filepath of the data when logged on the SRB server.

The serverLocalPath points to a filepath on the SRB server (the directory plus filename.) Most files are stored in the SRB Vault, but this file can be stored anywhere on the server that you have permissions. You must have a user account on the SRB server machine, and that account must have read/write permissions to this abstract filepath.


query

public MetaDataRecordList[] query(java.lang.String fieldName)
                           throws java.io.IOException
Queries metadata specific to this SRBFile object and selects one metadata value, fieldName, to be returned.

Parameters:
fieldName - The string name used to form the select object.
Returns:
The metadata values for this file refered to by fieldName
Throws:
java.io.IOException

query

public MetaDataRecordList[] query(java.lang.String[] fieldNames)
                           throws java.io.IOException
Queries metadata specific to this SRBFile object.

Overrides:
query in class GeneralFile
Parameters:
fieldNames - The string names used to form the select objects.
Returns:
The metadata values for this file refered to by fieldNames
Throws:
java.io.IOException

query

public MetaDataRecordList[] query(MetaDataSelect select)
                           throws java.io.IOException
Queries metadata specific to this SRBFile object and selects one metadata value, select, to be returned.

Throws:
java.io.IOException

query

public MetaDataRecordList[] query(MetaDataSelect[] selects)
                           throws java.io.IOException
Queries metadata specific to this SRBFile object.

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

query

public MetaDataRecordList[] query(MetaDataSelect[] selects,
                                  int recordsWanted)
                           throws java.io.IOException
Throws:
java.io.IOException

query

public MetaDataRecordList[] query(MetaDataCondition[] conditions,
                                  MetaDataSelect[] selects)
                           throws java.io.IOException
Description copied from class: GeneralFile
Queries the file server to find all files that match a set of conditions. For all those that match, the fields indicated in the select array are returned in the result object.

While condition and select array objects have all been checked for self-consistency during their construction, there are additional problems that must be detected at query time:

For instance, it is possible to build a condition object appropriate for the SRB, then pass that object in a local file system query. That will find that the condition is incompatible and generate a mismatch exception.

Query is implemented by the file-server-specific classes, like that for the SRB, FTP, etc. Those classes must re-map condition and select field names and operator codes to those required by a particular file server and protocol version. Once re-mapped, they issue the query and get results. The results are then mapped back to the standard public field names of the MetaDataGroups. So, if a MetaDataGroup uses a name like "file path", but the SRB calls it "data name", then query maps first from "file path" to "data name" before issuing the query, and then from "data name" back to "file path" within the results. The programmer using this API should never see the internal field names.

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

query

public MetaDataRecordList[] query(MetaDataCondition[] conditions,
                                  MetaDataSelect[] selects,
                                  int recordsWanted)
                           throws java.io.IOException
Throws:
java.io.IOException

modifyMetaData

public void modifyMetaData(MetaDataRecordList record)
                    throws java.io.IOException
Change the values of the metadata associated with this file object. Not all metadata values can be modified. Also not all metadata value types apply to every object, i.e. directories and files have different metadata types. The following is a list of modifiable metadata types: (see also SRBMetaDataSet) CONTAINER_FOR_DIRECTORY
DIRECTORY_NAME
FILE_ANNOTATION
FILE_ANNOTATION_POSITION
DIRECTORY_ANNOTATION
FILE_AUDITFLAG
FILE_CHECKSUM
FILE_CLASS_NAME
FILE_COMMENTS
FILE_EXPIRE_DATE_2
FILE_EXPIRY_DATE
FILE_HIDE
FILE_IS_COMPRESSED
FILE_IS_ENCRYPTED
FILE_LAST_ACCESS_TIMESTAMP
FILE_LOCK_NUM
FILE_NAME
FILE_PIN_VAL
FILE_REPLICATION_ENUM
FILE_TYPE_NAME
INDEX_NAME_FOR_DATATYPE
INDEX_NAME_FOR_DIRECTORY
INDEX_NAME_FOR_FILE
IS_DIRTY
METHOD_NAME_FOR_DATATYPE
METHOD_NAME_FOR_DIRECTORY
METHOD_NAME_FOR_FILE
MODIFICATION_DATE
OFFSET
OWNER
PATH_NAME
SIZE
DEFINABLE_METADATA_FOR_FILES
DEFINABLE_METADATA_FOR_DIRECTORIES

note: Dates timestamps are Strings with the format: YYYY-MM-DD-HH.MM.SS

Overrides:
modifyMetaData in class GeneralFile
Throws:
java.io.FileNotFoundException - If the vault storage path can't be found. This can occur if the file was improperly deleted, removing the data on disk without removing the metadata.
java.io.IOException

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.

note: Files will be transferred using the SRB parallel transfer protocol. However, appending a file cannot use the parallel copy method. Also, the parallel method may be blocked by some firewalls, see also SRBFileSystem.setFirewallPorts( int, int )

Overrides:
copyTo in class GeneralFile
Parameters:
file - The file to receive the data.
forceOverwrite - If the file exists, force it to be overwritten. If the file cannot be overwritten throw IOException.
Throws:
java.lang.NullPointerException - If file is null.
java.io.IOException - If an IOException occurs.

copyTo

public void copyTo(GeneralFile file,
                   boolean forceOverwrite,
                   boolean bulkCopy)
            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.

note: Files will be transferred using the SRB parallel transfer protocol. However, appending a file cannot use the parallel copy method. Also, the parallel method may be blocked by some firewalls, see also SRBFileSystem.setFirewallPorts( int, int )

Parameters:
file - The file to receive the data.
forceOverwrite - If the file exists, force it to be overwritten. If the file cannot be overwritten throw IOException.
bulkCopy - If true, bulk copy: Default option, new ports may be opened. Files copied in parallel or bulk as appropriate.
If false, parallel copy: new ports may be opened, files copied in parallel but not in bulk.
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.

note: Files will be transferred using the SRB parallel transfer protocol. However, appending a file cannot use the parallel copy method. Also, the parallel method may be blocked by some firewalls, see also SRBFileSystem.setFirewallPorts( int, int )

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,
                     boolean bulkCopy)
              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.

note: Files will be transferred using the SRB parallel transfer protocol. However, appending a file cannot use the parallel copy method. Also, the parallel method may be blocked by some firewalls, see also SRBFileSystem.setFirewallPorts( int, int )

Parameters:
file - The file to receive the data.
bulkCopy - If true, bulk copy: Default option, new ports may be opened. Files copied in parallel or bulk as appropriate.
If false, parallel copy: new ports may be opened, files copied in parallel but not in bulk.
Throws:
java.lang.NullPointerException - If file is null.
java.io.IOException - If an IOException occurs.

fileCopyStatus

public long fileCopyStatus()
The number of bytes transfered so far by a currently executing SRBFile.copyTo/copyFrom command.

Returns:
the number of bytes that have been transfered so far.

getStat

public long[] getStat()
               throws java.io.IOException
Retrieves the platform independent stat structure. This is basically the POSIX stat definition.

Returns:
st_size = 0. File size in bytes (long).
st_dev = 1. Device.
st_ino = 2. Inode.
st_mode = 3. File mode.
st_nlink = 4. Number of links.
st_uid = 5. User ID of the file's owner.
st_gid = 6. Group ID of the file's group.
st_rdev = 7. ID of device.
This entry is defined only for character or block special files.
st_atim = 8. Time of last access.
Use st_atim instead of st_atime because in solaris, st_atime is
defined to be somthing else.
st_spare1 = 9.
st_mtime = 10. Time of last data modification.
st_spare2 = 11.
st_ctim = 12. Time of last file status change.
st_spare3 = 13.
Time measured in seconds since 00:00:00 GMT, Jan. 1, 1970.
st_blksize = 14. Optimal blocksize for file system i/o ops.
st_blocks = 15. Actual number of blocks allocated in DEV_BSIZE blocks.
st_vfstype = 16. Type of fs (see vnode.h).
st_vfs = 17. Vfs number.
st_type = 18. Vnode type.
st_gen = 19. Inode generation number.
st_flag = 20. Flag word.
Reserved1 = 21. Reserved.
Reserved2 = 22. Reserved.
st_access = 23. Process' access to file.
st_dummy = 24. pat to 32 bit boundary.
st_spare4 = 25+. Reserved.

Throws:
java.io.IOException - If an IOException occurs.

getPermissions

public java.lang.String getPermissions()
                                throws java.io.IOException
Get the permissions of the current user for this SRBFile: write, read, all, annotate or null.

Throws:
java.io.IOException - If an IOException occurs.

getPermissions

public MetaDataRecordList[] getPermissions(boolean allUsers)
                                    throws java.io.IOException
Gets all the non-null permissions of all SRB users for this SRBFile: write, read, all, annotate or null.

Throws:
java.io.IOException - If an IOException occurs.

changePermissions

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

Parameters:
permission - "w" - write;"r" - read;"rw" or "all" - read/write; "n" - null;"t" - annotate;"o" - owner;"c" - curate
newUserName - The permissions are changed for this user,
userMdasDomain - at this Mdas domain.
Throws:
java.io.IOException - If an IOException occurs.

changePermissions

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

Parameters:
permission - "w" - write;"r" - read;"rw" or "all" - read/write; "n" - null;"t" - annotate;"o" - owner;"c" - curate
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.

replicate

public void replicate(java.lang.String newResource)
               throws java.io.IOException
Replicates this SRBFile to a new resource. Each replicant will increment its replication number by 1 from the last replication. Directories/collections will be recursively replicated.

In SRB, one can make copies of a data set and store the copies in different locations. But, all these copies in SRB 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, SRB cycles through all the copies of the datset and reads the one that is accessible at that time. It uses a simple replica identification mechanism to order this list of replicated datasets.

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

backup

public void backup(java.lang.String backupResource)
            throws java.io.IOException
Backup a data object. Make a replica to the backup resource. Skip it if a good copy already exist.

Parameters:
backupResource - - The backup resource
Throws:
java.io.IOException

checksum

public java.lang.String checksum()
                          throws java.io.IOException
Checksum a SRB data file. If the chksum already already exists, do nothing and return the chksum value. If the chksum does not exist, compute and register it.

Overrides:
checksum in class GeneralFile
Returns:
the checksum value. Returns null if this SRBFile object is a directory.
Throws:
java.io.IOException

checksum

public java.lang.String checksum(boolean force)
                          throws java.io.IOException
Checksum a SRB data file. By default, if the chksum already exists, do nothing and return the chksum value. If the chksum does not exist, compute and register it.

Parameters:
force - If true force compute and register of chksum even if one already exists. If false compute chksum, but don't register if one already exists.
Returns:
the checksum value. Returns null if this SRBFile object is a directory.
Throws:
java.io.IOException

register

public void register(java.lang.String registeringObjectPath,
                     long dataSize)
              throws java.io.IOException
Registers the location of a file on a SRB physical resource. This SRBFile represents the logical location on the SRB. it will be linked to its physical storage resource at the path specified by registeringObjectPath.
Registers files that are created outside SRB but are accesible by SRB and are as yet unregistered. The files are not modified. The registeringObjectPath can be a path name in the physical resource file hierarchy. SRB should have at least 'read/write' access permission for registeringObjectPath. This is required as a security measure that objects are registered only by owners who are able to grant SRB write priveleges. One can always remove the 'write' permission once the object has been registered.
The second synopsis allows one to register another copy of an already existing (or registered) srbObjectName at the new location registeringObjectPath.
The TargetName can be a path name in the collection hierarchy. The object creation is done in the current collection, if TargetName is just an object-name. If a relative or absolute collection is given in TargetName, then the object is stored in that collection. The user should have 'write' access permission for the collection. '.' can be used as TargetName to denote the current collection.
If TargetName is a collection, then register(...) uses the names of the local files as SRB object names. The directory path of registeringObjectPath is not used in making the SRB object name.
If TargetName is an object-name (possibly with a collection path) and there are more than one local file to be copied then the TargetName is appended to the front of the local file names to make SRB object names.
The correct size parameter is needed for many other SRB operations. Hence we suggest that you give the correct size of the file using this option. If the size is not given, it will try to get it through a stat() call assuming the file is local. If this stat() failed, a value of 0 is chosen.

Parameters:
registeringObjectPath - The file/DB path of the data.
dataSize - The size of the dataset if known. 0 = unknown.
Throws:
java.io.IOException
See Also:
setResource(java.lang.String)

executeProxyCommand

public java.io.InputStream executeProxyCommand(java.lang.String command,
                                               java.lang.String commandArgs)
                                        throws java.io.IOException
Proxy Operation that executes a command. The results of the command will be returned by the InputStream. The protocol of the return value on the InputStream depends on the command that was run. The InputStream is opened on a different port than the main SRB connection. It can be read independently of other SRB calls.
Calls the SRBFileSystem function of the same name.

Parameters:
command - The command to run.
commandArgs - The command argument string.
Returns:
any byte stream output.
Throws:
java.io.IOException - If an IOException occurs.
See Also:
SRBFileSystem.executeProxyCommand(java.lang.String, java.lang.String)

link

public void link(SRBFile newLink)
          throws java.io.IOException
Links newLink with this object as the source. The user should have at least 'read' access permission for the target.

Throws:
java.io.IOException

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

delete

public boolean delete(boolean force)
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.

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

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

getName

public java.lang.String getName()
Overrides:
getName in class GeneralFile
Returns:
The name of the file or directory denoted by this abstract pathname.

getPath

public java.lang.String getPath()
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. 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

isContainer

public boolean isContainer()
Tests whether the file denoted by this abstract pathname is a SRB container.

Returns:
true if and only if the file denoted by this abstract pathname exists and is a container; 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

isDirectory

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

Parameters:
update - If true, send a new query to the SRB to determine if this abstract pathname refers to a directory. 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

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 milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs

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 SRBFile 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 SRBFile.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. The array will be empty if the directory is empty. Returns null if an I/O error occurs.

list

public java.lang.String[] list(MetaDataCondition[] conditions)
Returns the array of strings naming the files and directories in the directory denoted by this abstract pathname and which match a query formed using these conditions.

Overrides:
list in class GeneralFile
See Also:
list()

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
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 SRBFile.

setLastModified

public boolean setLastModified(long time)
                        throws java.lang.IllegalArgumentException
This method will only change the lastModified time to the current time. The SRB will overwrite the input from this method

Overrides:
setLastModified in class GeneralFile
Parameters:
time - The new last-modified time, measured in a system-dependent way.
Throws:
java.lang.IllegalArgumentException - - If the argument is negative

setReadOnly

public boolean setReadOnly()
Marks the file or directory named by this abstract pathname so that only read operations are allowed. After invoking this method the file or directory is guaranteed not to change until it is either deleted or marked to allow write access. Whether or not a read-only file or directory may be deleted depends upon the underlying system. This operation is not possible on the SRB. File permissions can only be changed on a per user basis. Changing the file permissions for everyone is not possible.

Overrides:
setReadOnly in class GeneralFile

toURI

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

The exact form of the URI is according to the SRB. If it can be determined that the file denoted by this abstract pathname is a directory, then the resulting URI will end with a slash.

For a given abstract pathname f, it is guaranteed that

new SRBFile ( f.toURI()).equals( f)
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. However, this relationship typically does not hold 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.

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:
SRBFile(java.net.URI), URI, URI.toURL()

toURL

public java.net.URL toURL()
                   throws java.net.MalformedURLException
Converts this abstract pathname into a file: URL. The exact form of the URL is is according to the SRB. If it can be determined that the file denoted by this abstract pathname is a directory, then the resulting URL will end with a slash.

Usage note: This method does not automatically escape characters that are illegal in URLs. It is recommended that new code convert an abstract pathname into a URL by first converting it into a URI, via the toURI method, and then converting the URI into a URL via the URI.toURL method.

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:
toURI(), URI, URI.toURL(), URL

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