net.sf.cotta
Class ControlledFileSystem

java.lang.Object
  extended by net.sf.cotta.ControlledFileSystem
All Implemented Interfaces:
FileSystem
Direct Known Subclasses:
CatastrophicFileSystem

public class ControlledFileSystem
extends java.lang.Object
implements FileSystem

A file system that delegates all file operations to a controller

See Also:
ControlledFileSystem.Controller

Nested Class Summary
static interface ControlledFileSystem.Controller
           
static class ControlledFileSystem.PermissionController
           
 
Field Summary
protected  ControlledFileSystem.Controller controller
           
 
Constructor Summary
ControlledFileSystem(FileSystem fileSystem, ControlledFileSystem.Controller controller)
           
 
Method Summary
 int compare(TPath path1, TPath path2)
          Compares the two path
 void createDir(TPath path)
           
 void createFile(TPath path)
          Create file pointed by the given path
 java.nio.channels.FileChannel createInputChannel(TPath path)
           
 java.io.InputStream createInputStream(TPath path)
           
 java.nio.channels.FileChannel createOutputChannel(TPath path, java.io.OutputStream outputStream)
           
 java.io.OutputStream createOutputStream(TPath path, OutputMode mode)
           
 void deleteDirectory(TPath path)
           
 void deleteFile(TPath path)
           
 boolean dirExists(TPath path)
           
 boolean equals(TPath path1, TPath path2)
          Check if two paths are equal.
 boolean fileExists(TPath path)
           
 long fileLastModified(TPath path)
           
 long fileLength(TPath path)
           
 int hashCode(TPath path)
          Returns the hash code for the path
 PathContent list(TPath path)
          List the content of the path
 void moveDirectory(TPath source, TPath destination)
           
 void moveFile(TPath source, TPath destination)
           
static FileSystem pathControlledFileSystem(FileSystem fileSystem, TPath pathAllowed)
           
 java.lang.String pathString(TPath path)
           
static FileSystem readOnlyFileSystem(FileSystem fileSystem)
           
 java.lang.String toCanonicalPath(TPath path)
           
 java.io.File toJavaFile(TPath path)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

controller

protected ControlledFileSystem.Controller controller
Constructor Detail

ControlledFileSystem

public ControlledFileSystem(FileSystem fileSystem,
                            ControlledFileSystem.Controller controller)
Method Detail

fileExists

public boolean fileExists(TPath path)
Specified by:
fileExists in interface FileSystem

createFile

public void createFile(TPath path)
                throws TIoException
Description copied from interface: FileSystem
Create file pointed by the given path

Specified by:
createFile in interface FileSystem
Parameters:
path - path of the file to create
Throws:
TIoException - error in creating the file

deleteFile

public void deleteFile(TPath path)
                throws TIoException
Specified by:
deleteFile in interface FileSystem
Throws:
TIoException

dirExists

public boolean dirExists(TPath path)
Specified by:
dirExists in interface FileSystem

createDir

public void createDir(TPath path)
               throws TIoException
Specified by:
createDir in interface FileSystem
Throws:
TIoException

list

public PathContent list(TPath path)
                 throws TIoException
Description copied from interface: FileSystem
List the content of the path

Specified by:
list in interface FileSystem
Parameters:
path - path
Returns:
path content, which contains a list of paths for the files and a list of paths for the directories
Throws:
TIoException - exception from the system. For example, when a direcotry does not exist, a physical system will throw the exception

createInputStream

public java.io.InputStream createInputStream(TPath path)
                                      throws TIoException
Specified by:
createInputStream in interface FileSystem
Throws:
TIoException

createInputChannel

public java.nio.channels.FileChannel createInputChannel(TPath path)
                                                 throws TIoException
Specified by:
createInputChannel in interface FileSystem
Throws:
TIoException

createOutputStream

public java.io.OutputStream createOutputStream(TPath path,
                                               OutputMode mode)
                                        throws TIoException
Specified by:
createOutputStream in interface FileSystem
Throws:
TIoException

createOutputChannel

public java.nio.channels.FileChannel createOutputChannel(TPath path,
                                                         java.io.OutputStream outputStream)
                                                  throws TIoException
Specified by:
createOutputChannel in interface FileSystem
Throws:
TIoException

deleteDirectory

public void deleteDirectory(TPath path)
                     throws TIoException
Specified by:
deleteDirectory in interface FileSystem
Throws:
TIoException

moveFile

public void moveFile(TPath source,
                     TPath destination)
              throws TIoException
Specified by:
moveFile in interface FileSystem
Throws:
TIoException

moveDirectory

public void moveDirectory(TPath source,
                          TPath destination)
                   throws TIoException
Specified by:
moveDirectory in interface FileSystem
Throws:
TIoException

pathString

public java.lang.String pathString(TPath path)
Specified by:
pathString in interface FileSystem

fileLength

public long fileLength(TPath path)
Specified by:
fileLength in interface FileSystem

fileLastModified

public long fileLastModified(TPath path)
Specified by:
fileLastModified in interface FileSystem

compare

public int compare(TPath path1,
                   TPath path2)
Description copied from interface: FileSystem
Compares the two path

Specified by:
compare in interface FileSystem
Parameters:
path1 - path one
path2 - path two
Returns:
the comparing result used for sort

equals

public boolean equals(TPath path1,
                      TPath path2)
Description copied from interface: FileSystem
Check if two paths are equal. This is needed for cases like on Windows system "c:\a\b\c.txt" is the same as "C:\A\B\C.TXT" even though the case is different

Specified by:
equals in interface FileSystem
Parameters:
path1 - path one
path2 - path two
Returns:
true if the two paths are equal according to the file system

hashCode

public int hashCode(TPath path)
Description copied from interface: FileSystem
Returns the hash code for the path

Specified by:
hashCode in interface FileSystem
Parameters:
path - path
Returns:
hash code

toJavaFile

public java.io.File toJavaFile(TPath path)
Specified by:
toJavaFile in interface FileSystem

toCanonicalPath

public java.lang.String toCanonicalPath(TPath path)
Specified by:
toCanonicalPath in interface FileSystem

pathControlledFileSystem

public static FileSystem pathControlledFileSystem(FileSystem fileSystem,
                                                  TPath pathAllowed)

readOnlyFileSystem

public static FileSystem readOnlyFileSystem(FileSystem fileSystem)