com.borland.primetime.vfs
Class FileFilesystem

java.lang.Object
  |
  +--com.borland.primetime.vfs.AbstractFilesystem
        |
        +--com.borland.primetime.vfs.FileFilesystem

public class FileFilesystem
extends AbstractFilesystem
implements Filesystem

The FileFilesystem provides a direct mapping of Filesystem operations onto native file and directory access. The protocol, host and anchor portions of a Url are ignored by the file filesystem. It is assumed that the VFS will direct only "file" protocol Url actions to this filesystem, and that the file portion of the Url will contain an absolute path using forward slashes as directory separators regardless of the underlying operating system.


Field Summary
static FileFilesystem FILESYSTEM
           
static java.lang.String PROTOCOL
           
 
Fields inherited from interface com.borland.primetime.vfs.Filesystem
TYPE_BOTH, TYPE_DIRECTORY, TYPE_FILE
 
Method Summary
 void delete(Url url)
          Deletes the file respresented by the specified Url.
 boolean exists(Url url)
          Tests if the file represented by the specified Url actually exists.
 boolean fileEquals(Url url, Url otherUrl)
          Compares two file Urls based on the java.io.File objects provided by getFileObject.
 int fileHashCode(Url url)
          Provides a hashcode based on the java.io.File object produced by getFileObject.
 Url getAbsoluteUrl(java.lang.String newHost, java.lang.String absoluteFilePath)
          Assists in interpreting a relative path by creating a full Url for a file path if it represents an absolute path.
 Url getCanonicalUrl(Url url)
          Reports the actual filename for file represented by the specified Url.
 Url getChild(Url url, java.lang.String subpath)
          Creates a new Url that adds the specified subpath to an existing Url's file path.
 Url[] getChildren(Url url, RegularExpression[] patterns, int type)
          Retrieves a list of Urls representing files and other directories within the directory represented by the specified Url.
 java.io.File getFileObject(Url url)
          Returns a java.io.File object that corresponds to a given Url.
 java.io.InputStream getInputStream(Url url)
          Creates an InputStream that reads from the file represented by the specified Url.
 long getLastModified(Url url)
          Reports the time at which the file represented by the specified Url was last modified.
 java.io.OutputStream getOutputStream(Url url, boolean makeBackup)
          Creates an OutputStream that writes to the file represented by the specified Url.
 Url getParent(Url url)
          Returns a Url with the last subpath from the supplied Url's file path removed.
 java.lang.String getProtocol()
          Returns the name of the file protocol.
 java.lang.String getRelativePath(Url root, Url target, boolean onlyChildren)
          Create a relative path from an root Url to specified target Url.
 Url getRelativeUrl(Url root, java.lang.String relativePath)
          Create a new Url from an existing root Url and a relative component.
static void initOpenTool(byte majorVersion, byte minorVersion)
          OpenTool initialization
 boolean isDirectory(Url url)
          Tests if the filename represented by the specified Url is actually a directory.
 boolean isReadOnly(Url url)
          Tests if the file represented by the specified Url is read only.
 boolean isValid(Url url)
          Determines whether the state of a Url instance is valid.
 
Methods inherited from class com.borland.primetime.vfs.AbstractFilesystem
getName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL

public static final java.lang.String PROTOCOL

FILESYSTEM

public static final FileFilesystem FILESYSTEM
Method Detail

initOpenTool

public static void initOpenTool(byte majorVersion,
                                byte minorVersion)
OpenTool initialization

getProtocol

public java.lang.String getProtocol()
Returns the name of the file protocol.
Specified by:
getProtocol in interface Filesystem
Returns:
The value of FileFilesystem.PROTOCOL.

getInputStream

public java.io.InputStream getInputStream(Url url)
                                   throws java.io.IOException
Creates an InputStream that reads from the file represented by the specified Url.
Specified by:
getInputStream in interface Filesystem
Parameters:
url - The file to be read.
Returns:
The InputStream.
Throws:
java.io.IOException - If the Url specifies a resource that could not be read.
java.io.FileNotFoundException - If the Url specified does not map to an existing file.

getOutputStream

public java.io.OutputStream getOutputStream(Url url,
                                            boolean makeBackup)
                                     throws java.io.IOException
Creates an OutputStream that writes to the file represented by the specified Url. If requested, a backup file will be created by appending a tilde character to the current filename before writing. If a backup file already exists, it will be deleted without warning.
Specified by:
getOutputStream in interface Filesystem
Parameters:
url - The file to be written.
makeBackup - True if the filesystem should make a backup first.
Returns:
The OutputStream.
Throws:
java.io.IOException - If the Url specifies a resource that could not be written to.

isReadOnly

public boolean isReadOnly(Url url)
Tests if the file represented by the specified Url is read only.
Specified by:
isReadOnly in interface Filesystem
Parameters:
url - The file to be tested.
Returns:
True if the file is read-only, false if the file can be written to.

getLastModified

public long getLastModified(Url url)
Reports the time at which the file represented by the specified Url was last modified.
Specified by:
getLastModified in interface Filesystem
Parameters:
url - The file to be tested.
Returns:
The file's timestamp, or Buffer.MODIFIED_NEVER if the file does not exist.

getCanonicalUrl

public Url getCanonicalUrl(Url url)
Reports the actual filename for file represented by the specified Url. On Win32 this may result in a change in capitalization, on Unix the canonical Url is identical to the original Url.
Specified by:
getCanonicalUrl in interface Filesystem
Overrides:
getCanonicalUrl in class AbstractFilesystem
Parameters:
url - The file.
Returns:
The canonical representation of the file, or the original url if no matching file exists.

exists

public boolean exists(Url url)
Tests if the file represented by the specified Url actually exists.
Specified by:
exists in interface Filesystem
Parameters:
url - The file to be tested.
Returns:
True if the file exists, false otherwise.

delete

public void delete(Url url)
            throws java.io.IOException
Deletes the file respresented by the specified Url. Attempts to delete a read-only file fail.
Specified by:
delete in interface Filesystem
Parameters:
url - The file to be deleted.
Throws:
java.io.IOException - If the file specified could not be deleted.

isDirectory

public boolean isDirectory(Url url)
Tests if the filename represented by the specified Url is actually a directory.
Specified by:
isDirectory in interface Filesystem
Parameters:
url - The filename to be tested.
Returns:
True if the specified filename is a directory, false otherwise.

getChildren

public Url[] getChildren(Url url,
                         RegularExpression[] patterns,
                         int type)
Retrieves a list of Urls representing files and other directories within the directory represented by the specified Url.
Specified by:
getChildren in interface Filesystem
Parameters:
url - The directory to scan.
pattern - An array of regular expressions constraining the set of values that will be returned. Only children whose final path component exactly matches at least one of the patterns will be represented in the resulting array. Note that a null array matches all children and that directories are not compared against the patterns, only files.
type - The constants TYPE_DIRECTORY, TYPE_FILE, and TYPE_BOTH can be used to control the type of resources that are represented in the result array.
Returns:
An array of valid Url objects representing files and directories. If none exist, an empty Url array is returned.

getChild

public Url getChild(Url url,
                    java.lang.String subpath)
Creates a new Url that adds the specified subpath to an existing Url's file path. The new Url will typically retain the protocol and host of the existing Url, but will always lose the anchor component.

When a new subpath terminating in a square bracket is detected, the newly created Url will belong to the ZipFilesystem rather than the FileFilesystem, and a leading square bracket will be prepended to match the closing bracket.

Specified by:
getChild in interface Filesystem
Overrides:
getChild in class AbstractFilesystem
Parameters:
url - The existing Url.
subpath - The subpath to be added to the Url's file path.
Returns:
The newly created Url.

getParent

public Url getParent(Url url)
Returns a Url with the last subpath from the supplied Url's file path removed. The anchor for the parent Url is always set to null, but the filesystem and protocol are typically inherited from the supplied Url.
Specified by:
getParent in interface Filesystem
Overrides:
getParent in class AbstractFilesystem
Parameters:
url - The Url for which a parent is desired.
Returns:
The Url that serves as a logical parent the the supplied Url, or null if there is no parent Url, such as when the file path contains only a single subpath.

getAbsoluteUrl

public Url getAbsoluteUrl(java.lang.String newHost,
                          java.lang.String absoluteFilePath)
Assists in interpreting a relative path by creating a full Url for a file path if it represents an absolute path.
Overrides:
getAbsoluteUrl in class AbstractFilesystem
Returns:
The Url defined by the absolute path provided, or null if the path is not actually an absolute path.

fileHashCode

public int fileHashCode(Url url)
Provides a hashcode based on the java.io.File object produced by getFileObject.
Specified by:
fileHashCode in interface Filesystem
Overrides:
fileHashCode in class AbstractFilesystem
Parameters:
url - The Url for which a hashcode should be computed.
Returns:
The Url's hashcode.

fileEquals

public boolean fileEquals(Url url,
                          Url otherUrl)
Compares two file Urls based on the java.io.File objects provided by getFileObject. This provides compatibility with local filesystem rules for case sensitivity or lack thereof.
Specified by:
fileEquals in interface Filesystem
Overrides:
fileEquals in class AbstractFilesystem
Parameters:
url - The first of the Urls to compare.
otherUrl - The second of the Urls to compare.
Returns:
True if the Urls represent the same file, false otherwise.

getFileObject

public java.io.File getFileObject(Url url)
Returns a java.io.File object that corresponds to a given Url.
Specified by:
getFileObject in interface Filesystem
Overrides:
getFileObject in class AbstractFilesystem
Parameters:
url - The Url in question.
Returns:
The java.io.File object corresponding to the provided Url.

getRelativeUrl

public Url getRelativeUrl(Url root,
                          java.lang.String relativePath)
Create a new Url from an existing root Url and a relative component. This method doesn't need to process the anchor portion of the relative path since it has already been removed by the VFS.

Deals with the additional complications of zip-relative pathing, which may look like: [path1/path2]/path3/path4 by stripping off the leading square bracket using one of two techniques:


isValid

public boolean isValid(Url url)
Determines whether the state of a Url instance is valid. In addition to the basic requirements, the Url must not have a host component.
Specified by:
isValid in interface Filesystem
Overrides:
isValid in class AbstractFilesystem
Parameters:
url - The Url in question.
Returns:
True if the Url is valid, false otherwise.

getRelativePath

public java.lang.String getRelativePath(Url root,
                                        Url target,
                                        boolean onlyChildren)
Create a relative path from an root Url to specified target Url. The anchor portions are taken care of by the VFS and are guaranteed to be null in this method.
Specified by:
getRelativePath in interface Filesystem
Overrides:
getRelativePath in class AbstractFilesystem
Parameters:
root - The Url root.
target - The Url target.
onlyChildren - True if the target must be a descendant of the root, false if absolute paths and paths with leading "../" entries should be considered.
Returns:
The relative path to the target Url from this Url, or null if there is no valid path from the root Url to the target Url.