oscript.fs
Class AbstractFileSystem

java.lang.Object
  extended byoscript.fs.AbstractFileSystem
Direct Known Subclasses:
JarFileSystem, LocalFileSystem

public abstract class AbstractFileSystem
extends java.lang.Object

An interface implemented by something that can resolve AbstractFiles.

Version:
1.17
Author:
Rob Clark (rob@ti.com)

Nested Class Summary
protected static class AbstractFileSystem.BogusFile
          A non-existant file which is created to simulate non-existant directories that are in a path to a mount point, or files which simply don't exist.
static class AbstractFileSystem.MountPointFile
          A mount point file doesn't actually exist, but is used to simulate non existant components of the mount path of some file system.
 
Field Summary
static char SEPERATOR_CHAR
          The seperator character used for paths.
 
Constructor Summary
AbstractFileSystem()
           
 
Method Summary
static java.lang.String basename(java.lang.String path)
          Given a normalized path, return basename.
static java.util.Collection children(AbstractFile file)
          Get an iterator of the children of the specified file.
static java.util.Collection children(java.lang.String path)
          Get an iterator of the children of the specified file.
protected abstract  java.util.Collection childrenInFileSystem(java.lang.String mountPath, java.lang.String path)
          Return an iterator of children of the specified path.
static java.lang.String dirname(java.lang.String path)
          Given a normalized path, return dirname.
protected abstract  void flush()
          Flush any pending changes within this filesystem.
static java.lang.String getCwd()
          Get the current working directory.
protected  long lastModified()
          Return the last modification time of the root of the mount point itself.
static void mount(AbstractFileSystem fs, java.lang.String path)
          Mount a new filesystem.
static java.lang.String normalize(java.lang.String path)
          Normalize the path.
static java.lang.String normalize(java.lang.String cwd, java.lang.String path)
           
static AbstractFile resolve(java.lang.String path)
          Try to load the specified file from one of the mounted filesystems.
protected abstract  AbstractFile resolveInFileSystem(java.lang.String mountPath, java.lang.String path)
          Try to resolve the specified path.
static void setCwd(java.lang.String cwd)
          Set the current working directory.
protected static void touchMountPoint(AbstractFileSystem fs)
          When a file is created/deleted in the topmost directory in a mounted file system, it needs some way to cause the timestamp on the directory(s) it is mounted into to change.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEPERATOR_CHAR

public static final char SEPERATOR_CHAR
The seperator character used for paths. The implementation of the filesystem may translate this character into whatever is required for the native implementation of the filesystem.

See Also:
Constant Field Values
Constructor Detail

AbstractFileSystem

public AbstractFileSystem()
Method Detail

getCwd

public static java.lang.String getCwd()
Get the current working directory.

Returns:
string
See Also:
setCwd(java.lang.String)

setCwd

public static void setCwd(java.lang.String cwd)
                   throws java.io.IOException
Set the current working directory. If the path is not an absolute path, it is postpended to the current cwd. If the path does not exist, or is not a directory, this will throw IllegalArgumentException.

Parameters:
cwd - the new current working directory
Throws:
java.io.IOException - if the specified path is invalid.
See Also:
getCwd()

normalize

public static java.lang.String normalize(java.lang.String path)
Normalize the path. This involves ensuring the path is fully qualified (begins with "/"), and gets rid of any extra "." and "/".


normalize

public static java.lang.String normalize(java.lang.String cwd,
                                         java.lang.String path)

dirname

public static java.lang.String dirname(java.lang.String path)
Given a normalized path, return dirname. Ie. everything but the last component in the path.


basename

public static java.lang.String basename(java.lang.String path)
Given a normalized path, return basename. Ie. the last component of the path.


touchMountPoint

protected static void touchMountPoint(AbstractFileSystem fs)
                               throws java.io.IOException
When a file is created/deleted in the topmost directory in a mounted file system, it needs some way to cause the timestamp on the directory(s) it is mounted into to change.

Parameters:
fs - the filesystem that was modified
Throws:
java.io.IOException

mount

public static void mount(AbstractFileSystem fs,
                         java.lang.String path)
Mount a new filesystem. A filesystem can be mounted at any position within the virtual filesystem. A mounted filesystem could potentially eclipse a file. If multiple filesystems are mounted at the same point, the result is the union of all those filesystems.

Parameters:
fs - the filesystem to mount
path - the path to the location to mount (ex: "/")

resolve

public static AbstractFile resolve(java.lang.String path)
                            throws java.io.IOException
Try to load the specified file from one of the mounted filesystems.

Parameters:
path - the file to resolve
Throws:
java.io.IOException - if something goes wrong when reading file
See Also:
#addScriptPath(AbstractFileSystem)

children

public static java.util.Collection children(java.lang.String path)
                                     throws java.io.IOException
Get an iterator of the children of the specified file. If the specified file is not a directory, this will return an empty iterator.

Parameters:
path - the path to the file to get children of
Returns:
Collection of AbstractFile
Throws:
java.io.IOException
See Also:
children(AbstractFile)

children

public static java.util.Collection children(AbstractFile file)
                                     throws java.io.IOException
Get an iterator of the children of the specified file. If the specified file is not a directory, this will return an empty iterator.

Parameters:
file - the file to get children of
Returns:
Collection of AbstractFile
Throws:
java.io.IOException
See Also:
children(String)

resolveInFileSystem

protected abstract AbstractFile resolveInFileSystem(java.lang.String mountPath,
                                                    java.lang.String path)
                                             throws java.io.IOException
Try to resolve the specified path. If unresolved, return null. Note that this gets called under the synchronization of the abstract file system, so it does not need to be re-entrant.

Parameters:
mountPath - the path this fs is mounted at to resolve the requested file
path - path to file, relative to mountPath
Returns:
file or null
Throws:
java.io.IOException

childrenInFileSystem

protected abstract java.util.Collection childrenInFileSystem(java.lang.String mountPath,
                                                             java.lang.String path)
                                                      throws java.io.IOException
Return an iterator of children of the specified path.

Parameters:
mountPath - the path this fs is mounted at to resolve the requested file
path - path to file, relative to mountPath
Returns:
a collection of AbstractFile
Throws:
java.io.IOException

flush

protected abstract void flush()
                       throws java.io.IOException
Flush any pending changes within this filesystem.

Throws:
java.io.IOException

lastModified

protected long lastModified()
                     throws java.io.IOException
Return the last modification time of the root of the mount point itself. This is the same as the last modified time for the root of the filesystem.

Throws:
java.io.IOException