org.objectledge.filesystem
Interface FileSystemProvider

All Known Implementing Classes:
ClasspathFileSystemProvider, LocalFileSystemProvider, ReadOnlyFileSystemProvider

public interface FileSystemProvider

Specifies the contract between FileSystem abstarction and its concrete delegates.

Version:
$Id: FileSystemProvider.java,v 1.7 2005/10/06 08:38:38 rafal Exp $
Author:
rafal@caltha.pl

Method Summary
 boolean canRead(String path)
          Checks if the application is allowed to read given file or directory.
 boolean canWrite(String path)
          Checks if the application is allowed to write given file or directory.
 boolean checkPathChars(String path)
          Returns true if the given path contains acceptable characters.
 boolean createNewFile(String path)
          Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.
 void delete(String path)
          Deletes a file or directory.
 boolean exists(String path)
          Checks if the given file or directory exists.
 InputStream getInputStream(String path)
          Opens an input stream for reading a file.
 String getName()
          Returns the name of the provider.
 OutputStream getOutputStream(String path, boolean append)
          Opens an output stream for writing to file.
 RandomAccessFile getRandomAccess(String path, String mode)
          Returns a RandomAccess interface implementation for accessing the file at arbitrary positions.
 URL getResource(String path)
          Returns an URL to the resource.
 boolean isDirectory(String path)
          Checks if the given pathname points to a directory.
 boolean isFile(String path)
          Checks if the given pathname points to an ordinary file.
 boolean isReadOnly()
          Returns true if the provider is readonly.
 long lastModified(String path)
          Returns the time of the last modificaion of the specified file.
 long length(String path)
          Returns the size of the specified file.
 Set<String> list(String dir)
          Lists the files and directories inside a directory.
 void mkdirs(String path)
          Creates a directory, and all necceray parent directories.
 void rename(String from, String to)
          Atomically renames a file or directory.
 

Method Detail

getName

String getName()
Returns the name of the provider.

Returns:
name of the provider.

isReadOnly

boolean isReadOnly()
Returns true if the provider is readonly.

Returns:
true if the provider is readonly.

checkPathChars

boolean checkPathChars(String path)
Returns true if the given path contains acceptable characters.

Parameters:
path - the path.
Returns:
true if the given path contains acceptable characters.

exists

boolean exists(String path)
Checks if the given file or directory exists.

Parameters:
path - the path.
Returns:
true if the given file or directory exists.

isFile

boolean isFile(String path)
Checks if the given pathname points to an ordinary file.

Parameters:
path - the path
Returns:
true if the given pathname points to a directory.

isDirectory

boolean isDirectory(String path)
Checks if the given pathname points to a directory.

Parameters:
path - the path
Returns:
true if the given pathname points to a directory.

canRead

boolean canRead(String path)
Checks if the application is allowed to read given file or directory.

Parameters:
path - the path.
Returns:
true if the application is allowed to read given file or directory.

canWrite

boolean canWrite(String path)
Checks if the application is allowed to write given file or directory.

Parameters:
path - the path.
Returns:
true if the application is allowed to write given file or directory.

list

Set<String> list(String dir)
                 throws IOException
Lists the files and directories inside a directory.

Parameters:
dir - the directory.
Returns:
a list of names.
Throws:
IOException - if dir does not exist or is not a directory.

createNewFile

boolean createNewFile(String path)
                      throws IOException,
                             UnsupportedCharactersInFilePathException
Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.

The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file.

Parameters:
path - the pathname of the file to create.
Returns:
true if the named file does not exist and was successfully created; false if the named file already exists.
Throws:
UnsupportedCharactersInFilePathException - if the given path contains characters incompatible with underlying filesystem.
IOException - if the operation fails.

mkdirs

void mkdirs(String path)
            throws IOException,
                   UnsupportedCharactersInFilePathException
Creates a directory, and all necceray parent directories.

Parameters:
path - the path.
Throws:
UnsupportedCharactersInFilePathException - if the given path contains characters incompatible with underlying filesystem.
IOException - if the operation fails.

delete

void delete(String path)
            throws IOException
Deletes a file or directory.

Directories must be empty when being deleted.

Parameters:
path - the path.
Throws:
IOException - if the operation fails.

rename

void rename(String from,
            String to)
            throws IOException,
                   UnsupportedCharactersInFilePathException
Atomically renames a file or directory.

Parameters:
from - source path.
to - destination path.
Throws:
UnsupportedCharactersInFilePathException - if the given destination path contains characters incompatible with underlying filesystem.
IOException - if the operation fails.

getInputStream

InputStream getInputStream(String path)
Opens an input stream for reading a file.

Parameters:
path - the path.
Returns:
the InputStream or null if not available.

getOutputStream

OutputStream getOutputStream(String path,
                             boolean append)
Opens an output stream for writing to file.

Parameters:
path - the path.
append - true to append, false to truncate.
Returns:
the InputStream or null if not available.

getRandomAccess

RandomAccessFile getRandomAccess(String path,
                                 String mode)
Returns a RandomAccess interface implementation for accessing the file at arbitrary positions.

Parameters:
path - the abstract pathname.
mode - the string which defines the opening mode for this random access file, the form of this string is equal to the mode parameter in java.io.RandomAccessFile constructor.
Returns:
an RandomAccess interface implementation, or null if the operation is not supported.

getResource

URL getResource(String path)
                throws MalformedURLException
Returns an URL to the resource.

Parameters:
path - the abstract pathname.
Returns:
an URL to the resource, or null if not available.
Throws:
MalformedURLException - if the path contains invalid characters.

lastModified

long lastModified(String path)
Returns the time of the last modificaion of the specified file.

The time of the modification is returned as the number of milliseconds sice the epoch (Jan 1 1970), or -1L if the feature is not supported.

Parameters:
path - the path.
Returns:
the time of last modification of the specified file.

length

long length(String path)
Returns the size of the specified file.

Parameters:
path - the path.
Returns:
the size of the file in bytes, of -1 if not supported.


Copyright © 2003-2006 objectledge.org. All Rights Reserved.