org.objectledge.filesystem.impl
Class ReadOnlyFileSystemProvider

java.lang.Object
  extended by org.objectledge.filesystem.impl.ReadOnlyFileSystemProvider
All Implemented Interfaces:
FileSystemProvider
Direct Known Subclasses:
ClasspathFileSystemProvider

public abstract class ReadOnlyFileSystemProvider
extends Object
implements FileSystemProvider

A base class for read only FileSystem backend implemetations.

Version:
$Id: ReadOnlyFileSystemProvider.java,v 1.21 2006/02/08 18:22:33 zwierzem Exp $
Author:
Rafal Krzewski

Field Summary
private  Map<String,Object> directoryTree
          The directory tree.
private  Map<String,Long> lengths
          The file listing.
private  Map<String,Object> listing
          The file listing.
static String LISTING_ENCODING
          the character encoding used in file listings.
static String[] LISTING_LOCATION
          locations of the file listings, in order of precedence.
protected  String name
          Providers's name.
private  Map<String,Long> times
          The file listing.
 
Constructor Summary
ReadOnlyFileSystemProvider(String name)
          Creates an instance of the provider.
 
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.
abstract  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.
 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.
protected  void processListing(String location, InputStream is)
          Processes a listing.
protected  void processListings()
          Processes the liststings at the common locations.
 void rename(String from, String to)
          Atomically renames a file or directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.objectledge.filesystem.FileSystemProvider
getResource
 

Field Detail

LISTING_LOCATION

public static final String[] LISTING_LOCATION
locations of the file listings, in order of precedence.


LISTING_ENCODING

public static final String LISTING_ENCODING
the character encoding used in file listings.

See Also:
Constant Field Values

name

protected String name
Providers's name.


listing

private Map<String,Object> listing
The file listing.


directoryTree

private Map<String,Object> directoryTree
The directory tree.


times

private Map<String,Long> times
The file listing.


lengths

private Map<String,Long> lengths
The file listing.

Constructor Detail

ReadOnlyFileSystemProvider

public ReadOnlyFileSystemProvider(String name)
Creates an instance of the provider.

Parameters:
name - the name of the provider.
Method Detail

processListings

protected void processListings()
                        throws IOException
Processes the liststings at the common locations.

getInputStream(String) method must be functional at the point of calling this method.

Throws:
IOException - if the listings cannot be processed.

getName

public String getName()
Returns the name of the provider.

Specified by:
getName in interface FileSystemProvider
Returns:
name of the provider.

isReadOnly

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

Specified by:
isReadOnly in interface FileSystemProvider
Returns:
true if the provider is readonly.

processListing

protected void processListing(String location,
                              InputStream is)
                       throws IOException
Processes a listing.

Parameters:
location - the location of the listing
is - the stream used for reading the listing.
Throws:
IOException - if the index file cannot be processed.

checkPathChars

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

Specified by:
checkPathChars in interface FileSystemProvider
Parameters:
path - the path.
Returns:
true if the given path contains acceptable characters.

exists

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

Specified by:
exists in interface FileSystemProvider
Parameters:
path - the path.
Returns:
true if the given file or directory exists.

isFile

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

Specified by:
isFile in interface FileSystemProvider
Parameters:
path - the path
Returns:
true if the given pathname points to a directory.

isDirectory

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

Specified by:
isDirectory in interface FileSystemProvider
Parameters:
path - the path
Returns:
true if the given pathname points to a directory.

canRead

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

Specified by:
canRead in interface FileSystemProvider
Parameters:
path - the path.
Returns:
true if the application is allowed to read given file or directory.

canWrite

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

Specified by:
canWrite in interface FileSystemProvider
Parameters:
path - the path.
Returns:
true if the application is allowed to write given file or directory.

list

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

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

createNewFile

public boolean createNewFile(String path)
                      throws IOException
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.

Specified by:
createNewFile in interface FileSystemProvider
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:
IOException - if the operation fails.

mkdirs

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

Specified by:
mkdirs in interface FileSystemProvider
Parameters:
path - the path.
Throws:
IOException - if the operation fails.

delete

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

Directories must be empty when being deleted.

Specified by:
delete in interface FileSystemProvider
Parameters:
path - the path.
Throws:
IOException - if the operation fails.

rename

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

Specified by:
rename in interface FileSystemProvider
Parameters:
from - source path.
to - destination path.
Throws:
IOException - if the operation fails.

getInputStream

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

Specified by:
getInputStream in interface FileSystemProvider
Parameters:
path - the path.
Returns:
the InputStream or null if not available.

getOutputStream

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

Specified by:
getOutputStream in interface FileSystemProvider
Parameters:
path - the path.
append - true to append, false to truncate.
Returns:
the InputStream or null if not available.

getRandomAccess

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

Specified by:
getRandomAccess in interface FileSystemProvider
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.

lastModified

public 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.

Specified by:
lastModified in interface FileSystemProvider
Parameters:
path - the path.
Returns:
the time of last modification of the specified file.

length

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

Specified by:
length in interface FileSystemProvider
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.