|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface FileCacheManagerI
Document file cache manager.
Classes that implement this interface manage a set of document files in a
cache. The term document file is rather loosely defined, and denotes
any kind of data object that can be specified by a File
object
and which is uniquely identified by a document-ID string. Similarly,
the term cache is rather loosely defined, and denotes a collection of
one or more document files.
Usage
Classes that implement this interface should provide a no-argument (default) constructor:
class MyCacheManager implements FileCacheManagerI { // Constructor public MyCacheManager() { ... } ... }To create a cache that stores files in a cache, create a cache manager object, and establish the local cache directory and index file it should use:
try { FileCacheManagerI cache; File dir; dir = ...; cache = new MyCacheManager(); cache.open(dir, "mycache.idx"); } catch (IOException ex) { ... error ... }
New document files can be added to the cache:
try { File fname; String docId; docId = ...; fname = cache.createFile(id); } catch (IOException ex) { ... error ... }
The createFile(java.lang.String)
method creates a new file within the cache and returns
its name. The document-ID specified must be unique within the cache, i.e., no
other document file within the cache can have the same document-ID.
(A IOException
is thrown if the document-ID is not unique.)
The returned filename is guaranteed to be unique within the cache. From that
point on, there is a one-to-one correspondence between the document-ID and the
cached filename.
Data can be written to and read from the cached filename by client code.
Once the cached filename is no longer needed, it can be removed from the cache:
try { cache.removeFile(id); } catch (IOException ex) { ... error ... }
Once this is done, there is no longer any association between the document-ID and any filename in the cache.
Field Summary | |
---|---|
static java.lang.String |
REV
Revision information. |
Method Summary | |
---|---|
void |
close()
Close this cache manager. |
java.io.File |
createFile(java.lang.String docId)
Create a new cached filename in this cache for a given document-ID. |
java.io.File |
getFile(java.lang.String docId)
Retrieve the cached filename for a given document-ID within this cache. |
void |
open(java.io.File dir,
java.lang.String index)
Open the cache and initialize this cache manager. |
void |
removeAllFiles()
Remove all document files from this cache. |
void |
removeFile(java.lang.String docId)
Remove a given document file from this cache. |
Field Detail |
---|
static final java.lang.String REV
Method Detail |
---|
void open(java.io.File dir, java.lang.String index) throws java.io.IOException
dir
- A filename (which is typically the name of a local file directory) to be
used as the local file cache.index
- The name of the index (control) for the cache (which is typically the name
of a file residing in the cache). This can be null or empty
(""), in which case a default index is used.
java.io.IOException
- Thrown if access to the cache is denied or some other error occurs.close()
void close() throws java.io.IOException
java.io.IOException
- Thrown if access to the cache is denied or some other error occurs.open(java.io.File, java.lang.String)
java.io.File createFile(java.lang.String docId) throws java.io.IOException
docId
- A document-ID to create. This name must be unique within this cache.
java.io.IOException
- Thrown if document-ID docId already exists in the cache, or if
the cache could not be accessed, or if some other error occurs.getFile(java.lang.String)
,
removeFile(java.lang.String)
java.io.File getFile(java.lang.String docId) throws java.io.IOException
docId
- A document-ID to locate.
java.io.IOException
- Thrown if the document file does not exist, or if the cache could not be
accessed, or if some other error occurs.createFile(java.lang.String)
,
removeFile(java.lang.String)
void removeFile(java.lang.String docId) throws java.io.IOException
docId
- The document-ID of a document file to delete from this cache.
java.io.IOException
- Thrown if the document file does not exist, or if the cache could not be
accessed, or if some other error occurs.removeAllFiles()
void removeAllFiles() throws java.io.IOException
java.io.IOException
- Thrown if the cache could not be accessed, or if some other error occurs.removeFile(java.lang.String)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |