de.matthiasmann.twl.model
Interface FileSystemModel

All Known Implementing Classes:
JavaFileSystemModel

public interface FileSystemModel

An generic file system abstraction which is used as base for file system widgets like FolderBrowser.

See Also:
FileSelector, FolderBrowser

Nested Class Summary
static interface FileSystemModel.FileFilter
           
 
Field Summary
static java.lang.String SPECIAL_FOLDER_HOME
           
 
Method Summary
 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.
 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
 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 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
 

Field Detail

SPECIAL_FOLDER_HOME

static final java.lang.String SPECIAL_FOLDER_HOME
See Also:
Constant Field Values
Method Detail

getSeparator

java.lang.String getSeparator()
The separator character used to separate folder names in a path. This should be a string with one character.

Returns:
the separator character

getFile

java.lang.Object getFile(java.lang.String path)
Returns the object which represents the specified file name.

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

getParent

java.lang.Object getParent(java.lang.Object file)
Returns the parent folder of the specified file or folder

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

boolean isFolder(java.lang.Object file)
Returns true if the object is a valid folder in this file system

Parameters:
file - the object to check
Returns:
true if it is a folder

isFile

boolean isFile(java.lang.Object file)
Returns true if the object is a valid file in this file system

Parameters:
file - the object to check
Returns:
true if it is a file

isHidden

boolean isHidden(java.lang.Object file)
Checks if the specified object is a hidden file or folder.

Parameters:
file - the object to check
Returns:
true if it is a valid file or folder and is hidden

getName

java.lang.String getName(java.lang.Object file)
Returns the name of the specified object

Parameters:
file - the object to query
Returns:
the name or null if it was not a valid file or folder

getPath

java.lang.String getPath(java.lang.Object file)
Returns the path of the specified object

Parameters:
file - the object to query
Returns:
the path or null if it was not a valid file or folder
See Also:
getSeparator()

getRelativePath

java.lang.String getRelativePath(java.lang.Object from,
                                 java.lang.Object to)
Computes a relative path from from to to

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

getSize

long getSize(java.lang.Object file)
Returns the size of the file

Parameters:
file - the object to query
Returns:
the size of the file or -1 if it's not a valid file

getLastModified

long getLastModified(java.lang.Object file)
Returns the last modified date/time of the file or folder

Parameters:
file - the object to query
Returns:
the last modified date/time or 0
See Also:
System.currentTimeMillis()

equals

boolean equals(java.lang.Object file1,
               java.lang.Object file2)
Checks if the two objects specify the same file or folder

Parameters:
file1 - the first object
file2 - the second object
Returns:
true if they are equal

find

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

Parameters:
list - the list of objects
file - the object to search
Returns:
the index or -1 if it was not found

listRoots

java.lang.Object[] listRoots()
Lists all file system roots

Returns:
the file system roots

listFolder

java.lang.Object[] listFolder(java.lang.Object file,
                              FileSystemModel.FileFilter filter)
Lists all files or folders in the specified folder.

Parameters:
file - the folder to list
filter - an optional filter - can be null
Returns:
the (filtered) content of the folder

getSpecialFolder

java.lang.Object getSpecialFolder(java.lang.String key)
Locates a special folder like SPECIAL_FOLDER_HOME

Parameters:
key - the special folder key
Returns:
the object for this folder or null if it couldn't be located

openStream

java.io.InputStream openStream(java.lang.Object file)
                               throws java.io.IOException
Opens an InputStream for the specified file

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

openChannel

java.nio.channels.ReadableByteChannel openChannel(java.lang.Object file)
                                                  throws java.io.IOException
Opens a ReadableByteChannel for the specified file

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