public class BasicDataFileStore extends AbstractFileStore
FileStore
.Modifier and Type | Class and Description |
---|---|
protected static class |
BasicDataFileStore.DBEntry
Holds information for entries in the cache database.
|
protected class |
BasicDataFileStore.PostProcessor |
AbstractFileStore.StoreLocation
Modifier and Type | Field and Description |
---|---|
protected AbsentResourceList |
absentResources
Absent-resource list to keep track of resources that were requested by requestFile but failed.
|
protected java.util.List<java.lang.String> |
cacheContentTypes
The list of content types used to determine an unknown file format in
requestFile . |
protected BasicMemoryCache |
db
The map of cached entries.
|
protected static java.util.List<java.lang.String> |
DEFAULT_CACHE_CONTENT_TYPES
The default content types used to determine an unknown file format in
requestFile . |
protected static long |
TIMEOUT
The number of milliseconds to wait before a retrieval request for the same file can be reissued.
|
readLocations, writeLocation
Constructor and Description |
---|
BasicDataFileStore()
Create an instance.
|
BasicDataFileStore(java.io.File directoryPath)
Create an instance to manage a specified directory.
|
Modifier and Type | Method and Description |
---|---|
protected AbsentResourceList |
getAbsentResourceList()
Returns this file store's absent-resource list.
|
protected java.util.List<java.lang.String> |
getCacheContentTypes()
Returns this file store's list of content types.
|
java.lang.String |
getContentType(java.lang.String address)
Returns the content type of a cached file.
|
long |
getExpirationTime(java.lang.String address)
Returns the expiration time of a cached file.
|
protected int |
getJarLength(java.net.URL jarUrl)
Returns the length of the resource referred to by a jar URL.
|
protected java.net.URL |
getLocalFileUrl(java.lang.String address,
java.net.URL retrievalUrl,
boolean searchLocalCache)
Returns a file from the cache, the local file system or the classpath if the file exists.
|
protected void |
initialize(java.io.InputStream xmlConfigStream) |
protected java.lang.String |
makeCachePath(java.net.URL url,
java.lang.String contentType)
Makes a path to the file in the cache from the file's URL and content type.
|
protected java.lang.String |
makeGenericURLCachePath(java.net.URL url,
java.lang.String contentType)
Makes a path to the file in the cache from the file's generic URL and content type.
|
protected java.lang.String |
makeJarURLCachePath(java.net.URL jarURL,
java.lang.String contentType)
Makes a path to the file in the cache from the file's JAR URL and content type.
|
protected void |
makeLocal(java.lang.String address,
java.net.URL url,
boolean saveInLocalCache)
Retrieves a specified file and either adds it to the cache or saves it in a temporary file, depending on the
value of
saveInLocalCache . |
protected java.lang.String |
makeSuffix(java.lang.String path,
java.lang.String contentType)
Determines an appropriate suffix for a cached file.
|
protected java.io.File |
makeTempFile(java.net.URL url,
java.lang.String contentType)
Creates a temp file to hold the contents associated with a specified URL.
|
void |
removeFile(java.lang.String address)
Remove an entry from the file store.
|
protected java.lang.String |
removePrivateQueryParameters(java.lang.String queryString)
Removes any private parameters from the query string to ensure that those parameters are not written to the file
store as part of the cache name.
|
java.net.URL |
requestFile(java.lang.String address)
Requests a file.
|
java.net.URL |
requestFile(java.lang.String address,
boolean cacheRemoteFile)
Requests a file and specifies whether to store retrieved files in the cache or in a temporary location.
|
protected void |
updateEntry(java.lang.String address,
java.net.URL localFileUrl,
long expiration)
Updates a cache entry with information available once the file is retrieved.
|
addLocation, addLocation, buildLocationPath, buildReadPaths, buildWritePaths, containsFile, determineAllUserLocation, determineSingleUserLocation, doListFileNames, doListFileNames, findFile, getLocations, getUserHomeDir, getWriteLocation, isInstallLocation, listAllFileNames, listFile, listFileName, listFileNames, listTopFileNames, makeAbsoluteFile, makeAbsolutePath, markFileUsed, newFile, normalizeFileStoreName, propertyToPath, removeFile, removeLocation, storeLocationFor, storePathForFile
onMessage, propertyChange
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
onMessage
protected AbsentResourceList absentResources
getAbsentResourceList()
method may be overridden by subclasses if they wish to provide an alternatively configured absent-resource list.protected java.util.List<java.lang.String> cacheContentTypes
requestFile
. If a URL is
requested that does not have a format suffix, requestFile
appends a suffix appropriate for the
content type returned by the server. Subsequent calls to requestFile
use the content types in this
list to find the content type matching the cached file.
This is initialized to the following list of default content types typically used in WorldWind applications:
This list may be overridden by specifying a comma-delimited list of content types in the WorldWind configuration
parameter gov.nasa.worldwind.avkey.CacheContentTypes
.
protected BasicMemoryCache db
protected static final java.util.List<java.lang.String> DEFAULT_CACHE_CONTENT_TYPES
requestFile
.protected static final long TIMEOUT
public BasicDataFileStore()
java.lang.IllegalStateException
- if the configuration file name cannot be determined from Configuration
or
the configuration file cannot be found.public BasicDataFileStore(java.io.File directoryPath)
directoryPath
- the directory to manage as a file store.protected AbsentResourceList getAbsentResourceList()
protected java.util.List<java.lang.String> getCacheContentTypes()
public java.lang.String getContentType(java.lang.String address)
FileStore
address
- the file's address. If null, null is returned.public long getExpirationTime(java.lang.String address)
FileStore
address
- the file's address. If null, zero is returned.protected int getJarLength(java.net.URL jarUrl)
Note: This method causes the URL to open a connection and retrieve content length.
jarUrl
- the jar URL.protected java.net.URL getLocalFileUrl(java.lang.String address, java.net.URL retrievalUrl, boolean searchLocalCache)
JarURLConnection
for a description of jar URLs. If
searchLocalCache
is true
this looks for the file in the WorldWind cache, otherwise
this only looks for the file in the local file system and the classpath.address
- the name used to identify the cached file.retrievalUrl
- the URL to obtain the file if it is not in the cache. Used only to determine a location
to search in the local cache. May be null.searchLocalCache
- true
to look for the file in the WorldWind cache, otherwise
false
.java.lang.IllegalArgumentException
- if the specified address is null.protected void initialize(java.io.InputStream xmlConfigStream)
initialize
in class AbstractFileStore
protected java.lang.String makeCachePath(java.net.URL url, java.lang.String contentType)
url
- the URL to obtain the file.contentType
- the mime type of the file's contents.protected java.lang.String makeGenericURLCachePath(java.net.URL url, java.lang.String contentType)
host/hashCode/path_query.suffix
Otherwise, this returns a path name formatted as follows:
host/hashCode/path.suffix
Where host
is the name of the host machine, hashCode
is a four digit hash code computed
from the string "path" or "path_query" (if the URL has a query string), path
is the URL's path part,
query
is the URL's query string, and suffix
is either the path's suffix or a suffix
created from the specified content type. The hashCode
folder is used to limit the number of files
that appear beneath the host folder. This is necessary to avoiding the operating system's maximum file limit
should a large number of files be requested from the same host. If two URLs have the same hash code, then both
URLs are stored under the same hashCode
folder in the cache and are differentiated by their
path
and query
parts.
This removes any private parameters from the query string to ensure that those parameters are not written to the file store as part of the cache name. For example, the "CONNECTID" query parameter typically encodes a user's unique connection id, and must not be shared. Writing this parameter to the cache would expose that parameter to anyone using the same machine. If the query string is empty after removing any private parameters, it is ignored and only the path part of the URL is used as the filename.
url
- the URL to obtain the file.contentType
- the mime type of the file's contents.protected java.lang.String makeJarURLCachePath(java.net.URL jarURL, java.lang.String contentType)
host/path.suffix
Where host
is the path to the JAR file, path
is the file's path within the JAR archive,
and suffix
is either the path's suffix or a suffix created from the specified content type.
jarURL
- the URL to obtain the file. This URL is assumed to have the "jar" protocol.contentType
- the mime type of the file's contents.protected void makeLocal(java.lang.String address, java.net.URL url, boolean saveInLocalCache)
saveInLocalCache
.address
- the name used to identify the cached file.url
- the URL to obtain the file.saveInLocalCache
- true
to add the file to the cache, or false
to save it in a
temporary location.protected java.lang.String makeSuffix(java.lang.String path, java.lang.String contentType)
path
- the path whose suffix is to be validated if it exists.contentType
- the mime type of the data associated with the path.protected java.io.File makeTempFile(java.net.URL url, java.lang.String contentType)
url
- the URL to be associated with the temp file. Used only to determine an appropriate suffix.contentType
- the mime type of the file contents. Used to determine the file's suffix.public void removeFile(java.lang.String address)
FileStore.requestFile(String)
. The address
passed to this method must be the same as the address string that was
passed to requestFile
when the file was added.address
- file address of the entry to remove. This must be the same string as was passed to FileStore.requestFile(String)
.protected java.lang.String removePrivateQueryParameters(java.lang.String queryString)
This removes the key, the value, and any trailing parameter delimiter of all private parameters in the specified query string. Recognized private query parameters are as follows:
queryString
- the query string to examine.public java.net.URL requestFile(java.lang.String address)
URL
to the file. Otherwise if the specified address is a URL to a remote location, this
initiates a request for the file and returns null
. When the request succeeds the file is stored in
the local WorldWind cache and subsequent invocations of this method return a URL to the retrieved file.address
- the file address: either a local file, a URL, or a path relative to the root of the file store.null
.public java.net.URL requestFile(java.lang.String address, boolean cacheRemoteFile)
URL
to the
file. Otherwise if the specified address is a URL to a remote location, this initiates a request for the file and
returns null
. When the request succeeds the file is stored either in the local WorldWind cache or
in a temporary location and subsequent invocations of this method return a URL to the retrieved file.
The cacheRemoteFile
parameter specifies whether to store a retrieved remote file in the WorldWind
cache or in a temporary location. This parameter has no effect if the file exists locally. The temporary location
for a retrieved file does not persist between runtime sessions, and subsequent invocations of this method may not
return the same temporary location.
If a remote file is requested multiple times with different values for cacheRemoteFile
, it is
undefined whether the retrieved file is stored in the WorldWind cache or in a temporary location.
address
- the file address: either a local file, a URL, or a path relative to the root of the file
store.cacheRemoteFile
- true
to store remote files in the WorldWind cache, or false
to
store remote files in a temporary location. Has no effect if the address is a local file.null
.protected void updateEntry(java.lang.String address, java.net.URL localFileUrl, long expiration)
address
- the name used to identify the file in the cache.localFileUrl
- the path to the local copy of the file.expiration
- time (in milliseconds since the Epoch) at which this entry expires, or zero to indicate that
there is no expiration time.