Interface XFileAccessor
-
- All Known Implementing Classes:
XFileAccessor,XFileAccessor,XFileAccessor,XFileAccessor
public interface XFileAccessorThe XFileAccessor interface is implemented by filesystems that need to be accessed via 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.XFileAccessorA class prefix is added to this name. The default prefix is
com.sunand this composite name is located by the classLoader via the CLASSPATH. For instance, Sun's "nfs" XFileAccessor is installed as:com.sun.nfs.XFileAccessorThe default class prefix
com.suncan be changed by setting the System propertyjava.protocol.xfileto any desired prefix or a 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 via the CLASSPATH. This process will continue until the XFileAccessor is successfully loaded.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:
When an "ftp" URL is used, the following package names will be constructed:java.protocol.xfile=com.acme|com.abc(the default "com.sun" prefix is automatically added to the end of the property list)com.acme.ftp.XFileAccessor com.abc.ftp.XFileAccessor com.sun.ftp.XFileAccessorThe class loader 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:
In this case the "nfs" XFileAccessor from ABC, Inc. will be loaded in preference to Sun's NFS.com.acme.nfs.XFileAccessor com.abc.nfs.XFileAccessor com.sun.nfs.XFileAccessor- Version:
- 1.0, 04/08/98
- Author:
- Brent Callaghan
- See Also:
XFile
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleancanRead()Tests if the application can read from the specified file.booleancanWrite()Tests if the application can write to this file.voidclose()Close the file.booleandelete()Deletes the file specified by this object.booleanexists()Tests if this XFile object exists.voidflush()Forces any buffered output bytes to be written out.XFilegetXFile()Return the XFile for this AccessorbooleanisDirectory()Tests if the file represented by this XFileAccessor object is a directory.booleanisFile()Tests if the file represented by this object is a "normal" file.longlastModified()Returns the time that the file represented by thisXFileobject was last modified.longlength()Returns the length of the file represented by this XFileAccessor object.java.lang.String[]list()Returns a list of the files in the directory specified by this XFileAccessor object.booleanmkdir()Creates a directory whose pathname is specified by this XFileAccessor object.booleanmkfile()Creates an empty file whose pathname is specified by this XFileAccessor object.booleanopen(XFile xf, boolean serial, boolean readOnly)Open a file in this filesystem.intread(byte[] b, int off, int len, long foff)Reads a subarray as a sequence of bytes.booleanrenameTo(XFile dest)Renames the file specified by this XFileAccessor object to have the pathname given by the XFileAccessor object argument.voidwrite(byte[] b, int off, int len, long foff)Writes a sub array as a sequence of bytes.
-
-
-
Method Detail
-
open
boolean open(XFile xf, boolean serial, boolean readOnly)
Open 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, e.g. "nfs" and <location> is the location of the filesystem. 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 accessreadOnly- true if read only; false if read/write
-
getXFile
XFile getXFile()
Return the XFile for this Accessor
-
exists
boolean exists()
Tests if this XFile object exists.- Returns:
trueif the file specified by this object exists;falseotherwise.
-
canWrite
boolean canWrite()
Tests if the application can write to this file.- Returns:
trueif the application is allowed to write to a file whose name is specified by this object;falseotherwise.
-
canRead
boolean canRead()
Tests if the application can read from the specified file.- Returns:
trueif the file specified by this object exists and the application can read the file;falseotherwise.
-
isFile
boolean isFile()
Tests if the file represented by this object is a "normal" file.A file is "normal" if it 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:
trueif the file specified by this object exists and is a "normal" file;falseotherwise.
-
isDirectory
boolean isDirectory()
Tests if the file represented by this XFileAccessor object is a directory.- Returns:
trueif this XFileAccessor object exists and is a directory;falseotherwise.
-
lastModified
long lastModified()
Returns the time that the file represented by thisXFileobject 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
0Lif the specified file does not exist.
-
length
long length()
Returns the length of the file represented by this XFileAccessor object.- Returns:
- the length, in bytes, of the file specified by
this object, or
0Lif the specified file does not exist.
-
mkfile
boolean mkfile()
Creates an empty file whose pathname is specified by this XFileAccessor object.- Returns:
trueif the file was created;falseotherwise.
-
mkdir
boolean mkdir()
Creates a directory whose pathname is specified by this XFileAccessor object.- Returns:
trueif the directory could be created;falseotherwise.
-
renameTo
boolean renameTo(XFile dest)
Renames the file specified by this XFileAccessor object to have 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:
trueif the renaming succeeds;falseotherwise.
-
delete
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:
trueif the file is successfully deleted;falseotherwise.
-
list
java.lang.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).
-
read
int read(byte[] b, int off, int len, long foff) throws java.io.IOExceptionReads a subarray as a sequence of bytes.- Parameters:
b- the buffer into which the data is readoff- the start offset in the data bufferlen- the maximum number of bytes to be readfoff- the offset into the file- Returns:
- number of bytes read - zero if none.
- Throws:
java.io.IOException- If an I/O error has occurred.
-
write
void write(byte[] b, int off, int len, long foff) throws java.io.IOExceptionWrites a sub array as a sequence of bytes.- Parameters:
b- the data to be writtenoff- the start offset in the data in the bufferlen- the number of bytes that are writtenfoff- the offset into the file- Throws:
java.io.IOException- If an I/O error has occurred.
-
flush
void flush() throws java.io.IOExceptionForces any buffered output bytes to be written out.- Throws:
java.io.IOException- if an I/O error occurs.
-
close
void close() throws java.io.IOExceptionClose the file. 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:
java.io.IOException- If an I/O error has occurred.
-
-