com.trendmicro.grid.acl.ds
Interface FileContentRepository

All Superinterfaces:
Repository

public interface FileContentRepository
extends Repository

Defines an abstraction layer on top of a physical repository of files.

Version:
1.0
Author:
juergen_kellerer, 2010-05-05

Method Summary
 void attachProperties(byte[] hashKey, Map<String,String> properties)
          Attaches the specified properites to the file identified by the hash.
 byte[] createTemporaryHashKey()
          Creates a temporary hash key for the given file.
 byte[] decodeFromInternalURI(URI internalURI)
          Decodes the hash key from a sharable network or machine internal URI.
 byte[] decodeHashKey(String hashKey)
          Decodes the hash key from string.
 String encodeHashKey(byte[] hashKey)
          Encodes the hash key to string.
 URI encodeToInternalURI(byte[] hashKey)
          Encodes the hash key to a sharable network or machine internal URI.
 String getHashKeyAlgorithm()
          Returns the name of the MessageDigest algorithm used for creating hashKeys.
 Date getLastModified(byte[] hashKey)
          Returns the time of the last modification.
 boolean isExisting(byte[] hashKey)
          Returns true if the file exists inside the underlying repository.
 MessageDigest newHashKeyDigest()
          Returns a new instance of the MessageDigest used for creating hashKeys.
 InputStream openForRead(byte[] hashKey)
          Returns true if the file exists inside the underlying repository.
 DigestOutputStream openForWrite(byte[] hashKey)
          Opens the specified file for writing.
 Map<String,String> readProperties(byte[] hashKey)
          Reads previously attached properties.
 void rename(byte[] fromHashKey, byte[] toHashKey)
          Renames the specified resource, if possible.
 

Method Detail

getHashKeyAlgorithm

String getHashKeyAlgorithm()
Returns the name of the MessageDigest algorithm used for creating hashKeys.

Returns:
the name of the MessageDigest algorithm used for creating hashKeys.

newHashKeyDigest

MessageDigest newHashKeyDigest()
Returns a new instance of the MessageDigest used for creating hashKeys.

Returns:
a new instance of the MessageDigest used for creating hashKeys.

isExisting

boolean isExisting(byte[] hashKey)
Returns true if the file exists inside the underlying repository.

Parameters:
hashKey - the hash key identifying the file.
Returns:
true if the file exists inside the underlying repository.

getLastModified

Date getLastModified(byte[] hashKey)
Returns the time of the last modification.

Parameters:
hashKey - the hash key identifying the file.
Returns:
the time of the last modification or 'null' if the file doesn't exist.

openForWrite

DigestOutputStream openForWrite(byte[] hashKey)
                                throws FileNotFoundException,
                                       IllegalStateException
Opens the specified file for writing.

Note: The returned DigestOutputStream will compute the final hashKey during the write operation. out.getMessageDigest().digest() can be used to retrieve the final hashKey for a resource stored with a temporary key.

Parameters:
hashKey - the hash key identifying the file.
Returns:
a DigestOutputStream to write the content to.
Throws:
FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
IllegalStateException - In case of the repository doesn't allow to write to the specified resource. May happen in write once repositories, when an attempt is made to overwrite a resource)

attachProperties

void attachProperties(byte[] hashKey,
                      Map<String,String> properties)
                      throws IOException
Attaches the specified properites to the file identified by the hash.

Parameters:
hashKey - the hash key identifying the file.
properties - the properties to attach to the file.
Throws:
IOException - in case of attaching the properties failed.

openForRead

InputStream openForRead(byte[] hashKey)
                        throws FileNotFoundException
Returns true if the file exists inside the underlying repository.

Parameters:
hashKey - the hash key identifying the file.
Returns:
true if the file exists inside the underlying repository.
Throws:
FileNotFoundException - In case of the file, identified by the hashKey does not exist.

readProperties

Map<String,String> readProperties(byte[] hashKey)
                                  throws IOException
Reads previously attached properties.

Parameters:
hashKey - the hash key identifying the file.
Returns:
the properties attached to the file or 'null' if none were attached.
Throws:
FileNotFoundException - In case of the file, identified by the hashKey does not exist.
IOException

rename

void rename(byte[] fromHashKey,
            byte[] toHashKey)
            throws FileNotFoundException,
                   IllegalArgumentException
Renames the specified resource, if possible.

Parameters:
fromHashKey - The key identifying the resource to be renamed,
toHashKey - The new name of the resource.
Throws:
IllegalArgumentException - In case of a resource is renamed to a name that is considered invalid by the repository.
FileNotFoundException - In case of the file, identified by the hashKey does not exist.

createTemporaryHashKey

byte[] createTemporaryHashKey()
Creates a temporary hash key for the given file.

Returns:
true if the file exists inside the underlying repository.

encodeToInternalURI

URI encodeToInternalURI(byte[] hashKey)
Encodes the hash key to a sharable network or machine internal URI.

Parameters:
hashKey - the hash key identifying the file.
Returns:
a sharable network or machine internal URI.

decodeFromInternalURI

byte[] decodeFromInternalURI(URI internalURI)
Decodes the hash key from a sharable network or machine internal URI.

Parameters:
internalURI - a sharable network or machine internal URI.
Returns:
the decoded hash key, or 'null' if the URI is not identifying a file inside the repository.

encodeHashKey

String encodeHashKey(byte[] hashKey)
Encodes the hash key to string.

Parameters:
hashKey - the hash key identifying the file.
Returns:
a string version of the hashkey.

decodeHashKey

byte[] decodeHashKey(String hashKey)
Decodes the hash key from string.

Parameters:
hashKey - the hash key string.
Returns:
the hash key.