|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sourceforge.wohenchan.Cache
This class is the Facade class for all of the WoHenChan caching functionality. Given a directory, this class can cache various resources in that directory by name. Example usage:
Cache c = new Cache(System.getProperty("user.home")) if (c.contains("Unihan.txt")) { InputStream unihan = c.get("Unihan.txt"); } else { InputStream unihanStream; // open a socket to download unihan.txt try { c.put ("Unihan.txt", unihanStream); } catch (AlreadyCachedException e) { } }it will be important to decide whether or not this cache should try to deal with the Multiple JVM case (multiple JVMs munging on the same Cache object). Not only that, is it a good idea to control construction of Cache objects so that, for any given directory, there is at most one cache object? The current usage example doesn't even go this far. What if two threads get access to the same Cache object and both get output streams for the same cache object? As of right now, this object does not deal with these issues.
Field Summary | |
private java.io.File |
m_directoryName
|
private static Cache |
s_singleton
Singleton cache object which uses the .wohenchan subdirectory of the user's homedirectory. |
private static java.lang.String |
SUBDIR
Represents the directory in the users home directory to use for the singleton convenience cache. |
Constructor Summary | |
Cache(java.io.File directoryName)
|
|
Cache(java.lang.String directoryName)
|
Method Summary | |
boolean |
contains(java.lang.String resourceName)
|
private java.io.File |
dataFileForResource(java.lang.String resourceName)
|
java.io.InputStream |
get(java.lang.String resourceName)
Gets a stream corresponding to the resource named by the parameter. |
static Cache |
getInstance()
Singleton cache object which uses the .wohenchan subdirectory of the user's homedirectory. |
long |
length(java.lang.String resourceName)
|
void |
put(java.lang.String resourceName,
java.io.InputStream source)
associates the given resource name with the data that will appear on source. |
void |
put(java.lang.String resourceName,
java.io.InputStream source,
int expectedSize)
associates the given resource name with the data that will appear on source. |
private java.io.File |
sizeFileForResource(java.lang.String resourceName)
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private java.io.File m_directoryName
private static final java.lang.String SUBDIR
private static Cache s_singleton
Constructor Detail |
public Cache(java.lang.String directoryName)
public Cache(java.io.File directoryName)
Method Detail |
public static Cache getInstance()
private java.io.File sizeFileForResource(java.lang.String resourceName)
private java.io.File dataFileForResource(java.lang.String resourceName)
public java.io.InputStream get(java.lang.String resourceName) throws java.io.IOException
java.io.IOException
public void put(java.lang.String resourceName, java.io.InputStream source) throws java.io.IOException
resourceName
- the name to associate with the resourcesource
- the input stream from which to grab the cached
data
java.io.IOException
public void put(java.lang.String resourceName, java.io.InputStream source, int expectedSize) throws java.io.IOException
resourceName
- the name to associate with the resourcesource
- the input stream from which to grab the cached
dataexpectedSize
- the expected size of the data. The
authoritative size is taken from however many bytes are read
from source. This is used for making a guess as to what
progress has been made.
java.io.IOException
public boolean contains(java.lang.String resourceName)
public long length(java.lang.String resourceName) throws java.io.IOException
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |