org.sapia.filestorm.http
Class StoreClient

java.lang.Object
  extended by org.sapia.filestorm.http.StoreClient
All Implemented Interfaces:
Proto, Store

public class StoreClient
extends Object
implements Store, Proto

An instance of this class encapsulates access to a StoreServlet.

Author:
yduchesne

Nested Class Summary
static class StoreClient.StoreClientInputStream
           
 
Field Summary
 
Fields inherited from interface org.sapia.filestorm.http.Proto
HEADER_SAPIA_STORE_OP, OP_CONTAINS, OP_CONTENT_LEN, OP_LAST_MODIFIED, OP_LIST
 
Constructor Summary
StoreClient(String url, int bufsize)
           
 
Method Summary
 void close()
          Closes this instance.
 boolean contains(String name)
           
 void delete(String name)
           
 InputStream get(String name)
           
 void get(String name, OutputStream os)
          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.
 void put(String name, InputStream is)
          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
 

Constructor Detail

StoreClient

public StoreClient(String url,
                   int bufsize)
Parameters:
url - the URL of the StoreServlet to connect to.
bufsize - the size of the internal buffers that are used for data transfer.
Method Detail

close

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

Specified by:
close in interface Store

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

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

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

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.

get

public void get(String name,
                OutputStream os)
         throws IOException,
                FileNotFoundException
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.
os - an OutputStream to which the data is to be written.
Throws:
IOException - if an IO problem occurs while performing this operation.
FileNotFoundException - if no data exists for the given name.

get

public InputStream get(String name)
                throws IOException,
                       FileNotFoundException
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:
IOException - if an IO problem occurs while performing this operation.
FileNotFoundException - if no data exists for the given name.

put

public void put(String name,
                InputStream is)
         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.
is - an InputStream containing data to save.
Throws:
IOException - if an IO problem occurs while performing this operation.


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