|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectedu.sdsc.grid.io.GeneralFile
public class GeneralFile
An abstract representation of file and directory pathnames. This abstract class can be subclassed to create a generic file object which may refer to either a remote or local file.
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:
An optional system-dependent prefix string, such as a disk-drive specifier,
"/" for the UNIX root directory, or "\\" for a Microsoft Windows UNC
pathname, and
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.
The conversion of a pathname string to or from an abstract pathname is
inherently system-dependent. 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. The default name-separator character
is defined by the system property file.separator, and is made available
in the public static fields separator and separatorChar of this class.
When a pathname string is converted into an abstract pathname, the names
within it may be separated by the default name-separator character or by
any other name-separator character that is supported by the underlying
system.
A pathname, whether abstract or in string form, may be either absolute or relative. 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 this package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.
The prefix concept is used to handle root directories on UNIX platforms, and drive specifiers, root directories and UNC pathnames on Microsoft Windows platforms, as follows:
For UNIX platforms, 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.
For Microsoft Windows platforms, the prefix of a pathname that contains a drive specifier consists of the drive letter followed by ":" and possibly followed by "\" if the pathname is absolute. The prefix of a UNC pathname is "\\"; the hostname and the share name are the first two names in the name sequence. A relative pathname that does not specify a drive has no prefix.
Instances of the GeneralFile class are immutable; that is, once created, the abstract pathname represented by a GeneralFile object will never change.
File| Field Summary | |
|---|---|
static int |
BUFFER_MAX_SIZE
Default buffer size used for copyTo and copyFrom methods. |
protected java.util.Vector |
directory
Standardized, absolute directory string |
protected java.lang.String |
fileName
Standardized filename |
protected GeneralFileSystem |
fileSystem
Holds the server information used by this file. |
static java.lang.String |
PATH_SEPARATOR
Standard path separator character represented as a string for convenience. |
static char |
PATH_SEPARATOR_CHAR
The path separator character. |
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. |
| Constructor Summary | |
|---|---|
protected |
GeneralFile(GeneralFileSystem fileSystem,
java.lang.String dir,
java.lang.String fileName)
Creates a new GeneralFile from a parent pathname string and a child pathname string. |
protected |
GeneralFile(java.net.URI uri)
Creates a new GeneralFile 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. |
java.lang.String |
checksum()
If this abstract pathname refers to a file (and not a directory,) return the checksum of the file. |
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)
Deprecated. Doesn't always work without existing GeneralFile. Instead use GeneralFile.createTempFile(String, String, GeneralFile) |
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 |
firstQueryResult(java.lang.String fieldName)
Queries metadata specific to this file object, selecting one metadata value, fieldName, and returns the first result
of that query. |
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. |
GeneralFileSystem |
getFileSystem()
|
java.lang.String |
getName()
|
java.lang.String |
getParent()
|
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()
|
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. |
boolean |
isAbsolute()
Tests whether this abstract pathname is absolute in a system-dependant way. |
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(MetaDataCondition[] conditions)
|
GeneralFile[] |
listFiles()
Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname. |
static GeneralFile[] |
listRoots()
Deprecated. Doesn't work reliably without pre-existing fileSystem. use listRoots( GeneralFileSystem ) |
static GeneralFile[] |
listRoots(GeneralFileSystem fileSystem)
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. |
void |
modifyMetaData(MetaDataRecordList metaDataRecordList)
Used to modify 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(MetaDataSelect[] selectArray)
|
MetaDataRecordList[] |
query(java.lang.String[] metaDataFieldNames)
|
boolean |
renameTo(GeneralFile dest)
Renames the file denoted by this abstract pathname. |
protected void |
setDirectory(java.lang.String dir)
Abstract method to set the directory. |
protected void |
setFileName(java.lang.String fileName)
Abstract method to set the file name. |
protected void |
setFileSystem(GeneralFileSystem fileSystem)
Sets the file system used of this GeneralFile object. |
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 java.lang.Object |
|---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int BUFFER_MAX_SIZE
public static char separatorChar
file.separator. On UNIX systems the value of this
field is '/'; on Microsoft Windows systems it is '\\'.
System.getProperty(java.lang.String)public static java.lang.String separator
separatorChar.
public static char pathSeparatorChar
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 ';'.
System.getProperty(java.lang.String)public static java.lang.String pathSeparator
pathSeparatorChar.
public static java.lang.String PATH_SEPARATOR
PATH_SEPARATOR_CHAR.
public static char PATH_SEPARATOR_CHAR
protected GeneralFileSystem fileSystem
protected java.util.Vector directory
protected java.lang.String fileName
| Constructor Detail |
|---|
protected GeneralFile(GeneralFileSystem fileSystem,
java.lang.String dir,
java.lang.String fileName)
throws java.lang.NullPointerException
If parent is null then the new GeneralFile instance is created as if by invoking the single-argument GeneralFile 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 way defined by the subclass. If parent is the empty string then the new GeneralFile is created by converting child into an abstract pathname and resolving the result against the default directory of the subclass. Otherwise each pathname string is converted into an abstract pathname and the child abstract pathname is resolved against the parent.
fileSystem - The fileSystem used by this objectparent - The parent pathname stringchild - The child pathname string
java.lang.NullPointerException
protected GeneralFile(java.net.URI uri)
throws java.lang.NullPointerException,
java.lang.IllegalArgumentException
The exact form of a file: URI is system-dependent, hence the transformation performed by this constructor is also system-dependent.
For a given abstract pathname f it is guaranteed that
new GeneralFile( 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. This relationship typically does not hold, however, when a file: URI that is created in a virtual machine on one operating system is converted into an abstract pathname in a virtual machine on a different operating system.
uri - An absolute, hierarchical URI using a supported scheme,
eg. "file" or "srb".
java.lang.NullPointerException - if uri is null.
java.lang.IllegalArgumentException - If the preconditions on the parameter
do not hold.| Method Detail |
|---|
protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwable
protected void setFileSystem(GeneralFileSystem fileSystem)
throws java.lang.IllegalArgumentException,
java.lang.ClassCastException
fileSystem - The file system to be used.
java.lang.IllegalArgumentException - - if the argument is null.
java.lang.ClassCastException - -
if the argument is not an object of the approriate subclass.protected void setDirectory(java.lang.String dir)
dir - The directory path, need not be absolute.protected void setFileName(java.lang.String fileName)
fileName - The file name or fileName plus some or all of the
directory path.public java.lang.String getPathSeparator()
public char getPathSeparatorChar()
public GeneralFileSystem getFileSystem()
throws java.lang.NullPointerException
java.lang.NullPointerException - if fileSystem is null.
public java.lang.String firstQueryResult(java.lang.String fieldName)
throws java.io.IOException
fieldName, and returns the first result
of that query. Returns null if the query had no results.
fieldName - The string name used to form the select object.
fieldName
java.io.IOException
public MetaDataRecordList[] query(MetaDataCondition[] conditions,
MetaDataSelect[] selects)
throws java.io.IOException
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.
java.io.IOException
public MetaDataRecordList[] query(MetaDataSelect[] selectArray)
throws java.io.IOException
java.io.IOException
public MetaDataRecordList[] query(java.lang.String[] metaDataFieldNames)
throws java.io.IOException
java.io.IOException
public void modifyMetaData(MetaDataRecordList metaDataRecordList)
throws java.io.IOException
java.io.IOException
public void copyTo(GeneralFile file)
throws java.io.IOException
file - The file to receive the data.
java.lang.NullPointerException - If file is null.
java.io.IOException - If an IOException occurs.
public void copyTo(GeneralFile file,
boolean forceOverwrite)
throws java.io.IOException
file - The file to receive the data.
java.lang.NullPointerException - If file is null.
java.io.IOException - If an IOException occurs.
public void copyFrom(GeneralFile file)
throws java.io.IOException
file - The file to receive the data.
java.lang.NullPointerException - If file is null.
java.io.IOException - If an IOException occurs.
public void copyFrom(GeneralFile file,
boolean forceOverwrite)
throws java.io.IOException
file - The file to receive the data.
java.lang.NullPointerException - If file is null.
java.io.IOException - If an IOException occurs.
public java.lang.String checksum()
throws java.io.IOException
java.io.IOExceptionpublic boolean canRead()
true if and only if the file specified by this
abstract pathname exists and can be read; otherwise
false.public boolean canWrite()
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.public int compareTo(GeneralFile pathName)
pathname - The abstract pathname to be compared to this abstract
pathname
public int compareTo(java.lang.Object o)
throws java.lang.ClassCastException
compareTo(GeneralFile). Otherwise, it throws a
ClassCastException, since abstract pathnames can only be
compared to abstract pathnames.
compareTo in interface java.lang.Comparableo - The Object to be compared to this abstract
pathname
java.lang.ClassCastException - - if the argument is not an abstract pathname
public boolean createNewFile()
throws java.io.IOException
java.io.IOException
public static GeneralFile createTempFile(java.lang.String prefix,
java.lang.String suffix)
throws java.io.IOException,
java.lang.IllegalArgumentException
createTempFile(prefix, suffix, null).
prefix - The prefix string to be used in generating the file's
name; must be at least three characters longsuffix - The suffix string to be used in generating the file's
name; may be null, in which case the
suffix ".tmp" will be used
java.lang.IllegalArgumentException - If the prefix argument contains fewer than three
characters
java.io.IOException - If a file could not be created
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. If this method returns successfully then it is guaranteed that:
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
system-dependent default temporary-file directory will be used. The
default temporary-file directory is specified by the system property
java.io.tmpdir. On UNIX systems the default value of this
property is typically "/tmp" or "/var/tmp"; on
Microsoft Windows systems it is typically "c:\\temp". A different
value may be given to this system property when the Java virtual machine
is invoked, but programmatic changes to this property are not guaranteed
to have any effect upon the the temporary directory used by this method.
prefix - The prefix string to be used in generating the file's
name; must be at least three characters longsuffix - The suffix string to be used in generating the file's
name; may be null, in which case the
suffix ".tmp" will be useddirectory - The directory in which the file is to be created, or
null if the default temporary-file
directory is to be used
java.lang.IllegalArgumentException - If the prefix argument contains fewer than three
characters
java.io.IOException - If a file could not be createdpublic boolean delete()
public void deleteOnExit()
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. T
public boolean equals(java.lang.Object obj)
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.
equals in class java.lang.Objectobj - The object to be compared with this abstract pathname
true if and only if the objects are the same;
false otherwisepublic boolean exists()
true if and only if the file denoted by this
abstract pathname exists; false otherwisepublic GeneralFile getAbsoluteFile()
new GeneralFile(this.getAbsolutePath()()).
public java.lang.String getAbsolutePath()
public GeneralFile getCanonicalFile()
throws java.io.IOException
new GeneralFile(this.getCanonicalPath()()).
java.io.IOException - If an I/O error occurs, which is possible because the
construction of the canonical pathname may require
filesystem queries
public java.lang.String getCanonicalPath()
throws java.io.IOException
java.io.IOException - If an I/O error occurs, which is possible because the
construction of the canonical pathname may require
filesystem queriespublic java.lang.String getName()
public java.lang.String getParent()
public GeneralFile getParentFile()
null if this pathname does not name a parent
directory.
The parent of an abstract pathname consists of the pathname's prefix, if any, and each name in the pathname's name sequence except for the last. If the name sequence is empty then the pathname does not name a parent directory.
null if this pathname
does not name a parentpublic java.lang.String getPath()
public boolean isAbsolute()
true if this abstract pathname is absolute,
false otherwisepublic boolean isDirectory()
true if and only if the file denoted by this
abstract pathname exists and is a directory;
false otherwisepublic boolean isFile()
true if and only if the file denoted by this
abstract pathname exists and is a normal file;
false otherwisepublic boolean isHidden()
true if and only if the file denoted by this
abstract pathname is hidden.public long lastModified()
long value representing the time the file was
last modified, measured in system-dependent way.public long length()
0L if the file does not existpublic java.lang.String[] list()
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 GeneralFile object denotes a file, the results are unspecified.
public java.lang.String[] list(MetaDataCondition[] conditions)
public GeneralFile[] listFiles()
An array of GeneralFile objects is returned, one for each
file or directory in the directory. Pathnames denoting the directory
itself is included in the result. Each resulting abstract pathname is
constructed from this abstract pathname using the
GeneralFile(GeneralFile, String) constructor.
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.
public static GeneralFile[] listRoots()
listRoots( GeneralFileSystem )
It is guaranteed that the canonical pathname of any file physically present in the system will begin with one of the roots returned by this method.
GeneralFile objects denoting the
available filesystem root.public static GeneralFile[] listRoots(GeneralFileSystem fileSystem)
"/".
It is guaranteed that the canonical pathname of any file physically present in the SRB will begin with one of the roots returned by this method.
GeneralFile objects denoting the
SRB filesystem root, namely "/".public boolean mkdir()
public boolean mkdirs()
public boolean renameTo(GeneralFile dest)
throws java.lang.IllegalArgumentException,
java.lang.NullPointerException
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.
dest - The new abstract pathname for the named file
java.lang.IllegalArgumentException - If parameter dest is not a GeneralFile.
java.lang.NullPointerException - - If dest is null
public boolean setLastModified(long time)
throws java.lang.IllegalArgumentException
time - The new last-modified time, measured in a
system-dependent way.
java.lang.IllegalArgumentException - - If the argument is negativepublic boolean setReadOnly()
public java.lang.String toString()
toString in class java.lang.Objectpublic java.net.URI toURI()
The exact form of the URI is system-dependent. 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 GeneralFile
( 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.
GeneralFile(java.net.URI),
URI,
URI.toURL()
public java.net.URL toURL()
throws java.net.MalformedURLException
file: URL. The
exact form of the URL is system-dependent. 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.
java.net.MalformedURLException - If the path cannot be parsed as a URLtoURI(),
URI,
URI.toURL(),
URL
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||