com.binaryfantasy.murq.source
Class FSSource

java.lang.Object
  extended by com.binaryfantasy.murq.source.FSSource
All Implemented Interfaces:
ISource

public class FSSource
extends Object
implements ISource

An ISource implementation that utilizes a file system directory as it's data repostiory.

Author:
Bill Weiss

Constructor Summary
FSSource(File directory)
          Constructs a new instance using the specified directory.
FSSource(String path)
          Constructs a new instance using the specified path.
 
Method Summary
 void close()
          Called when a source is no longer to be used and provides a chance for clean up and release of resources.
 InputStream getInputStream(String key)
          Returns a stream to read the content specified by the key, or null if no content is associated with the key.
 Set<String> getKeys()
          Returns a Set of all current keys in this source, or an empty Set if there are none.
 OutputStream getOutputStream(String key)
          Returns a stream to write the content associated with the key.
 boolean remove(String key)
          Returns true if the content mapped to the provided key was removed, false if no content is associated with the key.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FSSource

public FSSource(String path)
         throws IOException
Constructs a new instance using the specified path. If the directory specified by the path does not exist, it will be created along with any needed ancestors.

Parameters:
path - file system path where data should be stored and accessed.
Throws:
IllegalArgumentException - if path points to a file and not a directory.
IOException

FSSource

public FSSource(File directory)
         throws IOException
Constructs a new instance using the specified directory. If the directory specified by the path does not exist, it will be created along with any needed ancestors.

Parameters:
directory - directory where data should be stored and accessed.
Throws:
IllegalArgumentException - if directory is null, or points to a file and not a directory.
IOException
Method Detail

close

public void close()
           throws IOException
Description copied from interface: ISource
Called when a source is no longer to be used and provides a chance for clean up and release of resources.

Specified by:
close in interface ISource
Throws:
IOException - if there is a problem during closing.

getKeys

public Set<String> getKeys()
                    throws IOException
Description copied from interface: ISource
Returns a Set of all current keys in this source, or an empty Set if there are none.

Specified by:
getKeys in interface ISource
Returns:
a Set of all current keys in this source, or an empty Set if there are none.
Throws:
IOException - if there is a problem reading the keys.

remove

public boolean remove(String key)
               throws IOException
Description copied from interface: ISource
Returns true if the content mapped to the provided key was removed, false if no content is associated with the key.

Specified by:
remove in interface ISource
Parameters:
key - unique value associated with the content.
Returns:
true if the content mapped to the provided key was removed, false if no content is associated with the key.
Throws:
IOException - if an error occurred while trying to remove the content.

getInputStream

public InputStream getInputStream(String key)
                           throws IOException
Description copied from interface: ISource
Returns a stream to read the content specified by the key, or null if no content is associated with the key.

Specified by:
getInputStream in interface ISource
Parameters:
key - unique value associated with the content.
Returns:
a stream to read the content specified by the key, or null if no content is associated with the key.
Throws:
IOException - if there is an error while getting the content stream for reading.

getOutputStream

public OutputStream getOutputStream(String key)
                             throws IOException
Description copied from interface: ISource
Returns a stream to write the content associated with the key.

Specified by:
getOutputStream in interface ISource
Parameters:
key - unique value associated with the content.
Returns:
a stream to write the content associated with the key.
Throws:
IOException - if there is an error while getting the content stream for writing.

toString

public String toString()
Overrides:
toString in class Object


Copyright (c) 2000-2006, BinaryFantasy.com