things.thinger.io.fs
Class FSFileSystem

java.lang.Object
  extended by things.thinger.io.fs.FSFileSystem
All Implemented Interfaces:
AFileSystem

public class FSFileSystem
extends java.lang.Object
implements AFileSystem

A disk File System implementation. You must specify the root during construction. Relative paths are not allowed and will result in an Error.

Version:
1.0

Version History

EPG - Initial - 18 MAR 05
 
Author:
Erich P. Gatejen

Field Summary
 
Fields inherited from interface things.thinger.io.AFileSystem
ROOT
 
Constructor Summary
FSFileSystem(java.lang.String root)
          Proper constructor.
 
Method Summary
static void completeDelete(java.io.File theFile, boolean recurse)
           
 boolean copy(java.lang.String path, java.io.InputStream is)
          Copy an InputStream to a file designated by the path.
 boolean delete(java.lang.String path, boolean recurse)
          Delete a file or directory if it exists at the path given.
 java.lang.String describeRoot()
          Describe the root to this filesystem.
 boolean exists(java.lang.String path)
          Report if a path exists at the path given.
 boolean isDirectory(java.lang.String path)
          Is this a directory?
 boolean isFile(java.lang.String path)
          Is this a file?
 void mkdir(java.lang.String path)
          Make the directory.
 java.io.InputStream openInputStream(java.lang.String path)
          Open a file with an InputStream for input.
 java.io.OutputStream openOutputStream(java.lang.String path)
          Open a file with an OutputStream for output
 java.util.List<java.lang.String> paths(java.lang.String path)
          Paths within the given root path.
 long size(java.lang.String path)
          Current size of the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FSFileSystem

public FSFileSystem(java.lang.String root)
             throws java.lang.Throwable
Proper constructor.

Parameters:
root - the path tot he root
Throws:
ThingsException
java.lang.Throwable
Method Detail

describeRoot

public java.lang.String describeRoot()
Describe the root to this filesystem. It may be an empty String.

Specified by:
describeRoot in interface AFileSystem
Returns:
A textual description for the root.

exists

public boolean exists(java.lang.String path)
Report if a path exists at the path given. It can be a file or a directory.

Specified by:
exists in interface AFileSystem
Parameters:
path - the path
Returns:
True if the file exists, otherwise false.

size

public long size(java.lang.String path)
Current size of the file. It can change.

Specified by:
size in interface AFileSystem
Parameters:
path - the path
Returns:
the size or 0 if the file doesn't exist or is invalid.

delete

public boolean delete(java.lang.String path,
                      boolean recurse)
               throws SystemException
Delete a file or directory if it exists at the path given.

Specified by:
delete in interface AFileSystem
Parameters:
path - An absolute path to the item.
recurse - If set true, it will delete sub-directories on a directory delete, otherwise it will just delete the files.
Returns:
true if the file existed, otherwise false.
Throws:
things.common.SystemException
SystemException

isFile

public boolean isFile(java.lang.String path)
Is this a file?

Specified by:
isFile in interface AFileSystem
Parameters:
path - the path to the file
Returns:
True if is a file, otherwise false.

isDirectory

public boolean isDirectory(java.lang.String path)
Is this a directory?

Specified by:
isDirectory in interface AFileSystem
Parameters:
path - the path
Returns:
True if is a directory, otherwise false.

paths

public java.util.List<java.lang.String> paths(java.lang.String path)
                                       throws SystemException
Paths within the given root path. It's how to find a directories contents.

Specified by:
paths in interface AFileSystem
Parameters:
path - the path
Returns:
An array of paths as Strings or null if the path is invalid.
Throws:
things.common.SystemException
SystemException

copy

public boolean copy(java.lang.String path,
                    java.io.InputStream is)
             throws SystemException
Copy an InputStream to a file designated by the path. It'll throw a ThingsException if something goes wrong. It will return true if it overwrote an existing file.

Specified by:
copy in interface AFileSystem
Parameters:
path - The path to the destination. If the file exists, it will be overwritten. If the path does not exist, it will be created.
is - An InputStream to the source. It should be buffered, so don't bother doing it.
Returns:
true if it overwrote a file, otherwise false
Throws:
things.common.SystemException
SystemException

openInputStream

public java.io.InputStream openInputStream(java.lang.String path)
                                    throws SystemException
Open a file with an InputStream for input. It will throw an exception for any problem.

Specified by:
openInputStream in interface AFileSystem
Parameters:
path - The past to the file to open.
Returns:
An InputStream that can read from the file.
Throws:
things.common.SystemException
SystemException

openOutputStream

public java.io.OutputStream openOutputStream(java.lang.String path)
                                      throws SystemException
Open a file with an OutputStream for output

Specified by:
openOutputStream in interface AFileSystem
Parameters:
path - The past to the file to open.
Returns:
An OutputStream that can read from the file.
Throws:
things.common.SystemException
SystemException

mkdir

public void mkdir(java.lang.String path)
           throws SystemException
Make the directory. If it already exists, nothing will happen. It will make all directories neccessary to finish the job.

Specified by:
mkdir in interface AFileSystem
Parameters:
path - The past to the file to open.
Throws:
things.common.SystemException
SystemException

completeDelete

public static void completeDelete(java.io.File theFile,
                                  boolean recurse)
                           throws java.lang.Throwable
Throws:
java.lang.Throwable


Things.