WebNFS Developer's Guide

URL Naming

Every filesystem type is identified by a URL of the general form described in RFC 1738 (ftp://ftp.isi.edu/in-notes/rfc/1738.txt). The extended filesystem uses the scheme name in the URL to automatically select a filesystem. For example, the NFS filesystem has the scheme name of "nfs." When presented with a filename string, the extended filesystem checks for a URL scheme followed by a colon at the beginning of the string. If it finds one, it uses the filesystem 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

Filenames 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 filesystem type indicated by the URL scheme name. For instance, a filename string of the form nfs://hostname/path is associated with the filesystem that has the scheme name of nfs. If the filename has no colon-separated prefix, or the scheme is not recognized then the name is assumed to belong to the default "native" scheme, that is, a URL prefix of native: is assumed and the name is handled by java.io.*. The two-argument constructor for XFile takes an XFile object and a filename:


XFile(Xfile dir, String filename)

The filename argument is interpreted according to the context set by the dir argument. The dir argument is used as a base URL and the name is evaluated as a relative URL. If the filename is an absolute URL, then the dir is ignored. If the filename is a relative URL, then it is combined with the base URL to form the name of the new XFile object. The rules that describe the evaluation of relative URLs are described in RFC 1808 (ftp://ftp.isi.edu/in-notes/rfc1808.txt).

Filesystem Selection

Filesystems are selected using these rules:

  1. If the XFile(String filename) constructor is used and the filename has a prepended URL scheme, the filesystem associated with that scheme is used; otherwise, the native filesystem is used.

  2. If the XFile(XFile dir, String filename) constructor is used, the filename is evaluated as a relative URL to the dir XFile.

Examples of File Name Usage and Filesystem Selection

The following examples show how the XFile constructors may be used:

XFile f1 = new XFile("nfs://hostname/directory1");

// NFS file based on an absolute URL

XFile f2 = new XFile("file.txt");

// not a URL, so defaults to the current directory of the "native" filesystem

XFile f4 = new XFile(f1,"text.html");

// evaluated relative to the base URL of f1 - which is "nfs".

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.