de.matthiasmann.twl.model
Class JavaFileSystemModel

java.lang.Object
  extended by de.matthiasmann.twl.model.JavaFileSystemModel
All Implemented Interfaces:
FileSystemModel

public class JavaFileSystemModel
extends java.lang.Object
implements FileSystemModel

A file system implementation which uses java.io.File as base.


Nested Class Summary
 
Nested classes/interfaces inherited from interface de.matthiasmann.twl.model.FileSystemModel
FileSystemModel.FileFilter
 
Field Summary
 
Fields inherited from interface de.matthiasmann.twl.model.FileSystemModel
SPECIAL_FOLDER_HOME
 
Constructor Summary
JavaFileSystemModel()
           
 
Method Summary
static int countLevel(FileSystemModel fsm, java.lang.Object file)
           
static int countLevel(FileSystemModel fsm, java.lang.Object parent, java.lang.Object child)
           
 boolean equals(java.lang.Object file1, java.lang.Object file2)
          Checks if the two objects specify the same file or folder
 int find(java.lang.Object[] list, java.lang.Object file)
          Finds the index of a file or folder in a list of objects.
 java.lang.Object getFile(java.lang.String path)
          Returns the object which represents the specified file name.
static JavaFileSystemModel getInstance()
           
 long getLastModified(java.lang.Object file)
          Returns the last modified date/time of the file or folder
 java.lang.String getName(java.lang.Object file)
          Returns the name of the specified object
 java.lang.Object getParent(java.lang.Object file)
          Returns the parent folder of the specified file or folder
 java.lang.String getPath(java.lang.Object file)
          Returns the path of the specified object
static java.lang.String getRelativePath(FileSystemModel fsm, java.lang.Object from, java.lang.Object to)
           
 java.lang.String getRelativePath(java.lang.Object from, java.lang.Object to)
          Computes a relative path from from to to
 java.lang.String getSeparator()
          The separator character used to separate folder names in a path.
 long getSize(java.lang.Object file)
          Returns the size of the file
 java.lang.Object getSpecialFolder(java.lang.String key)
          Locates a special folder like FileSystemModel.SPECIAL_FOLDER_HOME
 boolean isFile(java.lang.Object file)
          Returns true if the object is a valid file in this file system
 boolean isFolder(java.lang.Object file)
          Returns true if the object is a valid folder in this file system
 boolean isHidden(java.lang.Object file)
          Checks if the specified object is a hidden file or folder.
 java.lang.Object[] listFolder(java.lang.Object file, FileSystemModel.FileFilter filter)
          Lists all files or folders in the specified folder.
 java.lang.Object[] listRoots()
          Lists all file system roots
 java.nio.channels.ReadableByteChannel openChannel(java.lang.Object file)
          Opens a ReadableByteChannel for the specified file
 java.io.InputStream openStream(java.lang.Object file)
          Opens an InputStream for the specified file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaFileSystemModel

public JavaFileSystemModel()
Method Detail

getInstance

public static JavaFileSystemModel getInstance()

getSeparator

public java.lang.String getSeparator()
Description copied from interface: FileSystemModel
The separator character used to separate folder names in a path. This should be a string with one character.

Specified by:
getSeparator in interface FileSystemModel
Returns:
the separator character

getFile

public java.lang.Object getFile(java.lang.String path)
Description copied from interface: FileSystemModel
Returns the object which represents the specified file name.

Specified by:
getFile in interface FileSystemModel
Parameters:
path - the file path as returned by getPath()
Returns:
the object or null if the file was not found

getParent

public java.lang.Object getParent(java.lang.Object file)
Description copied from interface: FileSystemModel
Returns the parent folder of the specified file or folder

Specified by:
getParent in interface FileSystemModel
Parameters:
file - the file or folder - needs to be a valid file or folder
Returns:
the parent folder or null if the file parameter was invalid or was a root node

isFolder

public boolean isFolder(java.lang.Object file)
Description copied from interface: FileSystemModel
Returns true if the object is a valid folder in this file system

Specified by:
isFolder in interface FileSystemModel
Parameters:
file - the object to check
Returns:
true if it is a folder

isFile

public boolean isFile(java.lang.Object file)
Description copied from interface: FileSystemModel
Returns true if the object is a valid file in this file system

Specified by:
isFile in interface FileSystemModel
Parameters:
file - the object to check
Returns:
true if it is a file

isHidden

public boolean isHidden(java.lang.Object file)
Description copied from interface: FileSystemModel
Checks if the specified object is a hidden file or folder.

Specified by:
isHidden in interface FileSystemModel
Parameters:
file - the object to check
Returns:
true if it is a valid file or folder and is hidden

getName

public java.lang.String getName(java.lang.Object file)
Description copied from interface: FileSystemModel
Returns the name of the specified object

Specified by:
getName in interface FileSystemModel
Parameters:
file - the object to query
Returns:
the name or null if it was not a valid file or folder

getPath

public java.lang.String getPath(java.lang.Object file)
Description copied from interface: FileSystemModel
Returns the path of the specified object

Specified by:
getPath in interface FileSystemModel
Parameters:
file - the object to query
Returns:
the path or null if it was not a valid file or folder
See Also:
FileSystemModel.getSeparator()

getRelativePath

public java.lang.String getRelativePath(java.lang.Object from,
                                        java.lang.Object to)
Description copied from interface: FileSystemModel
Computes a relative path from from to to

Specified by:
getRelativePath in interface FileSystemModel
Parameters:
from - staring point for the relative path - must be a folder
to - the destination for the relative path
Returns:
the relative path or null if it could not be computed

getRelativePath

public static java.lang.String getRelativePath(FileSystemModel fsm,
                                               java.lang.Object from,
                                               java.lang.Object to)

countLevel

public static int countLevel(FileSystemModel fsm,
                             java.lang.Object file)

countLevel

public static int countLevel(FileSystemModel fsm,
                             java.lang.Object parent,
                             java.lang.Object child)

getLastModified

public long getLastModified(java.lang.Object file)
Description copied from interface: FileSystemModel
Returns the last modified date/time of the file or folder

Specified by:
getLastModified in interface FileSystemModel
Parameters:
file - the object to query
Returns:
the last modified date/time or 0
See Also:
System.currentTimeMillis()

getSize

public long getSize(java.lang.Object file)
Description copied from interface: FileSystemModel
Returns the size of the file

Specified by:
getSize in interface FileSystemModel
Parameters:
file - the object to query
Returns:
the size of the file or -1 if it's not a valid file

equals

public boolean equals(java.lang.Object file1,
                      java.lang.Object file2)
Description copied from interface: FileSystemModel
Checks if the two objects specify the same file or folder

Specified by:
equals in interface FileSystemModel
Parameters:
file1 - the first object
file2 - the second object
Returns:
true if they are equal

find

public int find(java.lang.Object[] list,
                java.lang.Object file)
Description copied from interface: FileSystemModel
Finds the index of a file or folder in a list of objects. This is potentially faster then looping over the list and calling FileSystemModel.equals(java.lang.Object, java.lang.Object)

Specified by:
find in interface FileSystemModel
Parameters:
list - the list of objects
file - the object to search
Returns:
the index or -1 if it was not found

listRoots

public java.lang.Object[] listRoots()
Description copied from interface: FileSystemModel
Lists all file system roots

Specified by:
listRoots in interface FileSystemModel
Returns:
the file system roots

listFolder

public java.lang.Object[] listFolder(java.lang.Object file,
                                     FileSystemModel.FileFilter filter)
Description copied from interface: FileSystemModel
Lists all files or folders in the specified folder.

Specified by:
listFolder in interface FileSystemModel
Parameters:
file - the folder to list
filter - an optional filter - can be null
Returns:
the (filtered) content of the folder

getSpecialFolder

public java.lang.Object getSpecialFolder(java.lang.String key)
Description copied from interface: FileSystemModel
Locates a special folder like FileSystemModel.SPECIAL_FOLDER_HOME

Specified by:
getSpecialFolder in interface FileSystemModel
Parameters:
key - the special folder key
Returns:
the object for this folder or null if it couldn't be located

openChannel

public java.nio.channels.ReadableByteChannel openChannel(java.lang.Object file)
                                                  throws java.io.IOException
Description copied from interface: FileSystemModel
Opens a ReadableByteChannel for the specified file

Specified by:
openChannel in interface FileSystemModel
Parameters:
file - the file object to read
Returns:
an ReadableByteChannel or null if the file object is not valid or a ReadableByteChannel can't be created
Throws:
java.io.IOException - if the file can't be read

openStream

public java.io.InputStream openStream(java.lang.Object file)
                               throws java.io.IOException
Description copied from interface: FileSystemModel
Opens an InputStream for the specified file

Specified by:
openStream in interface FileSystemModel
Parameters:
file - the file object to read
Returns:
an InputStream or null if the file object is not valid
Throws:
java.io.IOException - if the file can't be read