Document Contents: - Overview
|
Extended Filesystem API IntroductionDemand for distributed file system protocols, such as the WebNFSTM protocol, is coming from several areas. Network computer vendors have realized that network file systems can add a powerful capability to their products. Experienced JavaTM application developers want access to all the files the Internet has to offer in the same way. To meet this demand, several vendors are working on distributed file systems, such as WebNFS, CIFS, and others. This document describes the Extended Filesystem API. The API provides a common interface for multiple file system types. Also, it allows for dynamic loading of file system implementations. The API includes a set of classes that are similar to those found in the java.io classes, and therefore provides a familiar programmatic means of accessing files, either locally or remotely. The API also provides a means to access file and file system specific information. StatusThe Extended Filesystem API is an evolving specification and is subject to change. RequirementsThe model requires the following:
OverviewThe extended file system provides extensibility through the use of:
The API defines two means of access to network files and file systems:
The API supports three categories of applications:
ArchitectureThe following picture shows the extended file system architecture. The XFile (com.sun.xfile.*) layer of the architecture mirrors the standard java.io.File* programmatic interfaces. Under this layer is a set of XFileAccessors. There is one XFileAccessor interface implementation for each file system being supported. Currently only NFS, file URLs, and native file systems are supported. The accessors implement the XFileAccessor interface. They are responsible for all aspects of file access. The API classes are responsible for multiplexing between the different file systems as requests are made from the application. Support for dynamic loading of file system classes is included in this release. Please refer to WebNFS XFileAccessor Interface Reference.
URL NamingEvery file system type is identified by a URL of general form described in RFC 1738. The extended file system uses the scheme name in the URL to provide for the automatic selection of a file system. For example, the NFS file system has a scheme name "nfs". When presented with a filename string, the extended file system checks for a URL scheme followed by a colon at the beginning of the string. If it finds one it uses the file system accessor class associated with that URL scheme. If it does not find one, it defaults to the "native" scheme for access through java.io.*. URL Names and Native Names
File names are assumed to be absolute URLs or relative URLs
as determined by a context. If a filename string begins
with a valid URL scheme name followed by a colon, then the
name is associated with the file system type indicated by
the URL scheme name. For instance, a filename string of
the form
The two argument constructor for XFile takes an XFile object and
a filename: File systems are selected using these rules:
File System RegistrationThe file system registration mechanism is dynamic. The classes will search for a file system factory based on the file system name specified in the URL. This factory produces XFileAccessors. The name of the file system must be a unique URL scheme. A list of available file systems can be generated by calling the
static method " Examples of File Name Usage and File System Selection
One point to be made from these examples is that the validity of a constructed XFile is made when the XFile is used, not when it is constructed. This is consistent with the java.io.File class. Direct Access to File System-Specific FeaturesA reference to the object implementing a file
system's specific features can be determined through the
class interface. The interface allows developers to directly call these
methods. By doing this, you are increasing the risk of
writing code that works only for one file system type so
its use is discouraged.
To obtain access to these features directly, use the public method
" import java.io.*; import com.sun.xfile.*; import com.sun.nfs.*; public class nfslogin { public static void main(String av[]) { try { XFile xf = new XFile(av[0]); nfsXFileExtensionAccessor nfsx = (nfsXFileExtensionAccessor) xf.getExtensionAccessor(); if (! nfsx.loginPCNFSD("pcnfsdsrv", "bob", "-passwd-")) { System.out.println("login failed"); return; } if (xf.canRead()) System.out.println("Read permission OK"); else System.out.println("No Read permission"); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(System.out); } } } Class DescriptionsThis section describes the additional methods that are not currently part of the java.io classes. For example, the first entry, called Xfile, describes the methods that are in the com.sun.xfile.XFile class but not in the java.io.File class. All com.sun.xfile classes that have a counterpart in the java.io classes are generally a superset of the java.io classes in the methods provided, not including constructors. File descriptors are not supported and constructors that use a java.io.File* class now use a com.sun.xfile.XFile* class. Also shown are the few new interfaces and classes defined by the extended file system. A complete description of the API can be found in the javadoc files included in the release. XFile - Counterpart Is java.io.File
XFileOutputStream - Counterpart Is FileOutputStream
XFileInputStream - Counterpart Is FileInputStream
XRandomAccessFile - Counterpart Is RandomAccessFile
XFilenameFilter - Counterpart Is FilenameFilter
XFileReader - Counterpart Is FileReader
XFileWriter- Counterpart Is FileWriter
File Interface ExamplesExtending existing programs to network file systems should be straight forward using the extensions provided. You simply replace declarations of type java.io.FileXYZ with the counterpart java.io.XFileXYZ. The following are a few simple examples of applications that use the APIs.Example #1 - Using Streams Interface import java.io.*; import java.net.*; import com.sun.xfile.*; XFile xf = new XFile("file.txt"); if (xf.isFile()) { System.out.println("file is file"); } if (xf.isDirectory()) { System.out.println("file is directory"); } XFileInputStream nfis = null; nfis = new XFileInputStream(xf); for (int count = 0; ; count++) { int val = (byte) nfis.read(); if (val == -1) break; System.out.write(val); } System.out.println("read " + count + " bytes "); Example #2 - Using XRandomAccessFile Interface import java.io.*; import java.net.*; import com.sun.xfile.*; // create connection to host XFile xf = new XFile("nfs://ian/simple.html"); XRandomAccessFile xraf = new XRandomAccessFile(xf,"r"); int count = 10; xraf.seek(count); System.out.println("Value at position " + count + " is " + (byte)xraf.read()); System.out.println("Current file position is " + xraf.getFilePointer()); xraf.seek(0); for (count = 0 ; count < 100 ; count++) { int val = xraf.read(); if (val == -1) break; System.out.print(val); } |
Last modified: July 29, 1998