|
Purple Code | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.purpletech.io.CachedFS
Cached File System: sits on top of a file system, loads files from disk and stores them in memory. Refreshes them if they've changed. Uses com.purpletech.util.Cache (which means that accessing an item resets its timeout clock).
Allows a filter (Loader) that processes files immediately after
they're loaded, turning them into interesting objects (like byte[]s
or XML documents). By default, the files are returned as String
objects (assuming they're text files), but that can easily change
by calling setLoader(new CachedFS.BinaryLoader())
which returns them as byte[]s. You can also create
your own Loader by implementing the CachedFS.Loader
interface. You can also register different loaders for different
file extensions (like .gif).
| Nested Class Summary | |
static class |
CachedFS.BinaryLoader
|
static interface |
CachedFS.Loader
Callback that processes a file, turning it into an object, as it's loaded. |
static interface |
CachedFS.Tester
Callback that provides an extra check as to whether a file needs to be reloaded. |
static class |
CachedFS.TextLoader
|
| Field Summary | |
protected Cache |
cache
|
static boolean |
verbose
|
| Constructor Summary | |
CachedFS()
JavaBean initializer -- must call setRoot immediately |
|
CachedFS(java.io.File root)
|
|
CachedFS(java.lang.String root)
|
|
| Method Summary | |
void |
delete(java.lang.String path)
|
long |
getCreated(java.lang.String path)
use JNI to find out the date the file was created -- not yet implemented |
java.lang.Object |
getFile(java.lang.String path)
Load a file, or use the cached version if the file hasn't changed. |
java.util.List |
getFilenames(java.lang.String path)
Get a list of all files in a given directory. |
long |
getLastModified(java.lang.String path)
|
long |
getModified(java.lang.String path)
|
java.util.List |
list(java.lang.String path)
convenience wrapper |
protected java.lang.Object |
loadFile(java.lang.String path,
java.io.File f)
|
static void |
main(java.lang.String[] args)
|
protected java.io.File |
makeFileObject(java.lang.String path)
|
void |
move(java.lang.String path,
java.lang.String topath)
|
void |
setCacheTimeout(long x)
|
void |
setLoader(CachedFS.Loader loader)
register a default loader. |
void |
setLoader(java.lang.String ext,
CachedFS.Loader loader)
register a loader for a given extension. |
void |
setRoot(java.io.File root)
|
void |
setRoot(java.lang.String root)
|
void |
setTester(CachedFS.Tester t)
|
java.io.OutputStream |
writeFile(java.lang.String path)
Make sure you close the OutputStream! Otherwise, the lock will remain. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static boolean verbose
protected Cache cache
| Constructor Detail |
public CachedFS()
public CachedFS(java.io.File root)
root - the root directorypublic CachedFS(java.lang.String root)
root - the root directory| Method Detail |
public void setCacheTimeout(long x)
public void setRoot(java.lang.String root)
root - the root directorypublic void setRoot(java.io.File root)
root - the root directorypublic void setLoader(CachedFS.Loader loader)
public void setLoader(java.lang.String ext,
CachedFS.Loader loader)
ext - the file extension to processloader - the Loader to process that type of filepublic void setTester(CachedFS.Tester t)
protected java.io.File makeFileObject(java.lang.String path)
public java.lang.Object getFile(java.lang.String path)
throws java.io.IOException
path - path to file, relative to fs root
java.io.IOException
protected java.lang.Object loadFile(java.lang.String path,
java.io.File f)
throws java.io.IOException
java.io.IOException
public java.io.OutputStream writeFile(java.lang.String path)
throws java.io.IOException
java.io.IOException
public java.util.List getFilenames(java.lang.String path)
throws java.io.IOException
path - directory to list
java.io.IOException
public java.util.List list(java.lang.String path)
throws java.io.IOException
java.io.IOException
public void delete(java.lang.String path)
throws java.io.IOException
java.io.IOException
public void move(java.lang.String path,
java.lang.String topath)
throws java.io.IOException
java.io.IOExceptionpublic long getLastModified(java.lang.String path)
public long getModified(java.lang.String path)
public long getCreated(java.lang.String path)
public static void main(java.lang.String[] args)
throws java.io.IOException
java.io.IOException
|
Documentation generated March 5 2003 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||