org.sapia.filestorm.file
Class FileStore

java.lang.Object
  extended by org.sapia.filestorm.file.FileStore
All Implemented Interfaces:
Store
Direct Known Subclasses:
CachingFileStore

public class FileStore
extends Object
implements Store

An instance of this class implements the Store interface over the file system.

It should be noted that the names used to perform put/get/delete operations will be interpreted as full paths in a hierarchical file structure. That is: a put operation with which a name such as dir1/dir2/file.txt is used will trigger the hierarchical creation of directories dir1 and dir2, under which data will be kept in the a file named file.txt.

Author:
yduchesne

Field Summary
protected  File _baseDir
           
protected  int _bufsz
           
protected  org.apache.commons.logging.Log _log
           
 
Constructor Summary
FileStore(File baseDir, int bufSize)
           
 
Method Summary
 void cleanup()
           
 void close()
          Closes this instance.
 boolean contains(String name)
           
 void delete(String name)
           
 InputStream get(String name)
           
 void get(String name, OutputStream out)
          Streams the data corresponding to the given name into the given stream.
 long getContentLength(String name)
           
 long getLastModified(String name)
           
 String[] list(String baseName)
          Returns the list of names corresponding to stored data, relative to the given base name.
 OutputStream put(String name)
           
 void put(String name, InputStream data)
          Stores the data corresponding to the given stream under the named passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_bufsz

protected int _bufsz

_baseDir

protected File _baseDir

_log

protected org.apache.commons.logging.Log _log
Constructor Detail

FileStore

public FileStore(File baseDir,
                 int bufSize)
          throws IOException
Parameters:
baseDir - the base directory of this instance.
bufSize - the size of buffers that are internally used for data transfer.
Throws:
IOException - if an IO problem occurs when creating the instance.
Method Detail

put

public void put(String name,
                InputStream data)
         throws IOException
Description copied from interface: Store
Stores the data corresponding to the given stream under the named passed in. The stream is closed by this method.

Specified by:
put in interface Store
Parameters:
name - the name under which to keep the passed in data.
data - an InputStream containing data to save.
Throws:
IOException - if an IO problem occurs while performing this operation.

put

public OutputStream put(String name)
                 throws IOException
Throws:
IOException

get

public InputStream get(String name)
                throws FileNotFoundException,
                       IOException
Specified by:
get in interface Store
Parameters:
name - the name corresponding to the data to retrieve.
Returns:
the stream of data corresponding to the given name.
Throws:
FileNotFoundException - if no data exists for the given name.
IOException - if an IO problem occurs while performing this operation.

get

public void get(String name,
                OutputStream out)
         throws FileNotFoundException,
                IOException
Description copied from interface: Store
Streams the data corresponding to the given name into the given stream. The stream is closed by this method.

Specified by:
get in interface Store
Parameters:
name - the name corresponding to the data to retrieve.
out - an OutputStream to which the data is to be written.
Throws:
FileNotFoundException - if no data exists for the given name.
IOException - if an IO problem occurs while performing this operation.

list

public String[] list(String baseName)
              throws IOException
Description copied from interface: Store
Returns the list of names corresponding to stored data, relative to the given base name. For example, given the following full name: some/path/to/file, the file fragment will be relative to some/path/to (therefore, passing some/path/to as a base name to this method would return all names immediately "under" that base name).

If the passed in base name is null or is an empty string, then the returned names will be returned relatively to the "root" of this instance.

Specified by:
list in interface Store
Parameters:
baseName - a base name.
Returns:
an array containing the names corresponding to data stored under the given base name.
Throws:
IOException

delete

public void delete(String name)
            throws IOException
Specified by:
delete in interface Store
Parameters:
name - the name corresponding to the data to delete.
Throws:
IOException - if an IO problem occurs while performing this operation.

contains

public boolean contains(String name)
                 throws IOException
Specified by:
contains in interface Store
Parameters:
name - the name corresponding to the data whose existence must be checked.
Returns:
true if data exists for the given name, false otherwise.
Throws:
IOException

getContentLength

public long getContentLength(String name)
                      throws FileNotFoundException,
                             IOException
Specified by:
getContentLength in interface Store
Parameters:
name - the name corresponding to the data whose length must be returned.
Returns:
a length, in bytes.
Throws:
FileNotFoundException
IOException

getLastModified

public long getLastModified(String name)
                     throws FileNotFoundException,
                            IOException
Specified by:
getLastModified in interface Store
Parameters:
name - the name corresponding to the data whose timestamp must be returned..
Returns:
the time, in millis, at which the data was last modified.
Throws:
FileNotFoundException
IOException

close

public void close()
Description copied from interface: Store
Closes this instance.

Specified by:
close in interface Store

cleanup

public void cleanup()


Copyright © 2007 Sapia Open Community, Inc. All Rights Reserved.