|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.calitha.io.URLContentCache
public class URLContentCache
An URLContentCache object represents a cache for files and other resources.
The cache can work with both local files and with other resources which are referenced by a URL that contains a supported protocol such as http and ftp.
Each URLContentCache object has a context which by default is set to the application startup directory. The context is used to create an URL if the resource has a relative URI.
The URLContentCache can be set to auto mode, which is on by default, to automatically add resources when they are requested.
| Constructor Summary | |
|---|---|
URLContentCache()
Creates a new URIFileCacher. |
|
| Method Summary | |
|---|---|
void |
add(File file)
Adds a file in the cache by using a File object. |
void |
add(String location)
Adds a resource to the cache by using a string location. |
void |
add(URL url)
Adds a resource to the cache by using an URL. |
void |
clear()
Clears the cache. |
boolean |
contains(String location)
Determines if this cache already has this location cached. |
boolean |
contains(URL url)
Determines if this cache already has this location cached. |
byte[] |
get(File file)
Gets a resource from the cache by specifying a file object. |
byte[] |
get(String location)
Gets a resource and possibly adds it to the cache. |
byte[] |
get(URL url)
Gets a resource and possibly adds it to the cache. |
boolean |
getAutoMode()
Gets current auto mode state. |
ByteArrayInputStream |
getBIStream(File file)
Gets the file from the cache as a byte input stream. |
ByteArrayInputStream |
getBIStream(String location)
Gets the resource from the cache as a byte input stream. |
ByteArrayInputStream |
getBIStream(URL url)
Gets the resource from the cache as a byte input stream. |
URL |
getContext()
Gets the context of the cacher. |
void |
setAutoMode(boolean value)
Sets auto mode on or off. |
void |
setContext(URL context)
Sets the context of the cacher. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public URLContentCache()
By default the auto mode is enabled and the context is the application startup directory.
| Method Detail |
|---|
public URL getContext()
This is used when a relative URL is being used to get or add a resource.
public void setContext(URL context)
This is used when a relative URL is being used to get or add a resource.
context - context
IllegalArgumentException - if an argument is nullpublic boolean getAutoMode()
If auto mode is true the resource is automatically cached when it is first requested (and has not been added yet).
public void setAutoMode(boolean value)
If auto mode is true the resource is automatically cached when it is first requested (and has not been added yet).
value - true switches auto mode on; false switches it offpublic boolean contains(URL url)
url - absolute resource location
IllegalArgumentException - if an argument is null
public boolean contains(String location)
throws MalformedURLException
The location is transformed into an absolute URL (using the context) if the location is relative. This ensures that a resource is only cached once even though the resource can be represented as a relative or an absolute URL.
location - absolute or relative URL location as a string
MalformedURLException - when the location cannot be
transformed into an URL
IllegalArgumentException - if an argument is null
public void add(String location)
throws IOException
The location can be absolute that contains a supported protocol. Or it can be relative in which case the context is being used to transform it into an absolute URL.
location - absolute or relative URL
IOException - thrown when the location cannot be transformed in an
URL, or if the resource cannot be read into the cache
IllegalArgumentException - if an argument is null
public void add(URL url)
throws IOException
The URL must contain a supported protocol.
url - absolute URL
IOException - thrown if the file cannot be read into the cache
IllegalArgumentException - if an argument is null
public void add(File file)
throws IOException
The file object file will be transformed into an URL first which functions as the key to store the resource in the cache.
file - file being added
IOException - thrown when the file cannot be read into the cache
IllegalArgumentException - if an argument is null
public byte[] get(URL url)
throws IOException
url - url of the requested resource
IOException - thrown if the file cannot be added (in auto mode)
IllegalArgumentException - if an argument is null
public byte[] get(String location)
throws IOException
If auto mode is on then the file is added to the cache if it was not in there already.
location - absolute or relative URL location
IOException - thrown if the location cannot be transformed into
an URL or the file cannot be added to the cache (in auto mode)
IllegalArgumentException - if an argument is null
public byte[] get(File file)
throws IOException
file - requested file
IOException - thrown if the file cannot be added (in auto mode)
IllegalArgumentException - if an argument is null
public ByteArrayInputStream getBIStream(String location)
throws IOException
If auto mode is on then the file is also added if it was not added yet.
location - absolute or relative URL location
IOException - thrown if the uri cannot be transformed into
an URL or the resource cannot be added (in auto mode)
IllegalArgumentException - if an argument is null
public ByteArrayInputStream getBIStream(URL url)
throws IOException
url - url of the requested file
IOException - thrown if the resource cannot be added (in auto mode)
IllegalArgumentException - if an argument is null
public ByteArrayInputStream getBIStream(File file)
throws IOException
file - requested file
IOException - thrown if the file cannot be transformed into
an URL or the file cannot be loaded
IllegalArgumentException - if an argument is nullpublic void clear()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||