[Prev] [Next]
The XFileAccessor Interface Class and Methods
public interface XFileAccessor
The XFileAccessor interface is implemented by filesystems that need to be accessed by way of the XFile API. Classes that implement this interface must be associated with a URL scheme that is structured according to the Common Internet Scheme syntax described in RFC 1738, an optional location part followed by a hierarchical set of slash-separated directories.
A class file that implements this interface must be named XFileAccessor and be installed in a directory named after the URL scheme that it implements. For instance, an XFileAccessor that provides file access through the HTTP protocol would be associated with the http URL and its class file would be called:
http.XFileAccessor
A class prefix is added to this name. The default prefix is com.sun and this composite name is located by the classLoader using the CLASSPATH. For instance, Sun's nfs XFileAccessor is installed as:
com.sun.nfs.XFileAccessor
The default class prefix com.sun can be changed by setting the System property java.protocols.xfile to any desired prefix or list of prefixes separated by vertical bars. Each prefix in the list will be used to construct a package name and the classLoader will attempt to load that package by way of the CLASSPATH. This process will continue until the XFileAccessor is successfully loaded.
Example
For instance, if you want to use the ftp XFileAccessor from Acme, Inc and the nfs XFileAccessor from ABC Inc., then you can set the System property as follows:
java.protocols.xfile=com.acme|com.abc
When an ftp URL is used, the following package names will be constructed:
com.acme.ftp.XFileAccessor
com.abc.ftp.XFileAccessor
com.sun.ftp.XFileAccessor
(the default com.sun prefix is automatically added to the end of the property list)
The classLoader attempts to load each of the constructed package names in turn relative to the CLASSPATH until it is successful.
A subsequent reference to an nfs URL will result in the following list of candidate package names:
com.acme.nfs.XFileAccessor
com.abc.nfs.XFileAccessor
com.sun.nfs.XFileAccessor
In this case, the nfs XFileAccessor from ABC, Inc. will be loaded in preference to Sun's NFS.
For the XFile interface documentation, refer to
XFile Java Docs
Methods
- canRead()
- public abstract boolean canRead()
- Verifies that the application can read from the specified file.
- Returns true if the file specified by this object exists and the application can read the file; false otherwise.
- canWrite()
- public abstract boolean canWrite()
- Verifies that the application can write to this file.
- Returns true if the application is allowed to write to a file specified by this object; false otherwise.
- close()
- public abstract void close() throws IOException
- Closes this file and releases any system resources associated with the file. After the file is closed, further I/O operations may throw IOException.
- Throws IOException if an I/O error has occurred.
- delete()
- public abstract boolean delete()
- Deletes the file specified by this object. If the target file to be deleted is a directory, it must be empty for deletion to succeed.
- Returns true if the file is successfully deleted; false otherwise.
- exists()
- public abstract boolean exists()
- Verifies that this XFile object exists.
- Returns true if the file specified by this object exists; false otherwise.
- flush()
- public abstract void flush() throws IOException
- Forces any buffered output bytes to be written out.
- Throws IOException if an I/O error has occurred.
- getXFile()
- public abstract XFile getXFile()
- Return the XFile for this Accessor.
- isDirectory()
- public abstract boolean isDirectory()
- Verifies that the file represented by this XFileAccessor object is a directory.
- Returns true if this XFileAccessor object exists and is a directory; false otherwise.
- isFile()
- public abstract boolean isFile()
- Verifies that the file represented by this object is a "normal" file. A "normal" file is one that is not a directory and, in addition, satisfies other system-dependent criteria. Any non-directory file created by a Java application is guaranteed to be a normal file.
- Returns true if the file specified by this object exists and is a "normal" file; false otherwise.
- lastModified()
- public abstract long lastModified()
- Returns the time that the file represented by this XFile object was last modified. It is measured as the time in milliseconds since midnight, January 1, 1970 UTC.
- Returns the time the file specified by this object was last modified, or 0L if the specified file does not exist.
- length()
- public abstract long length()
- Returns the length, in bytes, of the file specified by this object, or 0L if the specified file does not exist.
- list()
public abstract String[] list()
Returns a list of the files in the directory specified by this XFileAccessor object.
Returns an array of file names in the specified directory. This list does
not include the current directory or the parent directory ("." and ".." on UNIX systems).
- mkdir()
- public abstract boolean mkdir()
- Creates a directory, the pathname of which is specified by this XFileAccessor object.
- Returns true if the directory could be created; false otherwise.
- mkfile()
public abstract boolean mkfile()
Creates an empty file, the pathname of which is specified by this XFileAccessor object.
Returns true if the file could be created; false otherwise.
- open(XFile, boolean,boolean)
- public abstract boolean open(XFile xf,boolean serial,boolean readOnly)
- Opens a file in this filesystem. This method is called before any other method. It may be used to open the real file.
- Parameters:
- xf - The XFile for the file to be accessed The URL will be of the form
- <proto>://<location>/<path>
- where <proto> is the name of the filesystem (for example, nfs) and <location> is the filesystem location. For nfs, this is the network name of a server. The <path> is a pathname that locates the file within <location>. As required by RFC 1738, the component delimiters in the pathname are as for URL syntax: forward slashes only.
- serial - true if serial access; false if random access.
- readOnly - true if read only; false if read/write.
- read(byte[],int, int,long)
- public abstract int read(byte b[],int off,int len,long foff) throws IOException
- Reads a subarray as a sequence of bytes.
- Parameters:
- b - the buffer into which the data is read.
- off - the start offset in the data buffer.
- len - the maximum number of bytes to be read.
- foff - the offset into the file.
- Returns number of bytes read - zero if none.
- Throws IOException if an I/O error has occurred.
- renameTo(XFile)
- public abstract boolean renameTo(XFile dest)
- Renames the file specified by this XFileAccessor object with the pathname given by the XFileAccessor object argument. The destination XFile object will be of the same URL scheme as this object. The change of name must not affect the existence or accessibility of this object.
- Parameters:
- dest - the new filename.
- Returns true if the renaming succeeds; false otherwise.
- write(byte[],int, int,long)
- public abstract void write(byte b[],int off,int len,long foff) throws IOException
- Writes a sub array as a sequence of bytes.
- Parameters:
- b - the data to be written.
- off - the start offset in the data in the buffer.
- len - the number of bytes that are written.
- foff - the offset into the file.
- Throws IOException if an I/O error has occurred.
[Prev] [Next]
Send comments to:
webnfs-feedback@sun.com
Copyright © 1998-99, Sun Microsystems, Inc.
901 San Antonio Rd., Palo Alto, CA 94303 USA