Package net.sourceforge.jnlp.cache
Class CacheUtil
java.lang.Object
net.sourceforge.jnlp.cache.CacheUtil
Provides static methods to interact with the cache, download
indicator, and other utility methods.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanstatic voidThis will remove all old cache items.static booleanClears the cache by deleting all the Netx cache files Note: Because of how our caching system works, deleting jars of another javaws process is using them can be quite disasterous.static booleanclearCache(String application, boolean jnlpPath, boolean domain) static FilegetCachedResourceFile(URL location, Version version, UpdatePolicy policy) This is returning File object of cached resource originally from URLstatic URLgetCachedResourceURL(URL location, Version version, UpdatePolicy policy) Caches a resource and returns a URL for it in the cache; blocks until resource is cached.static FilegetCacheFile(URL source, Version version) Returns the file for the locally cached contents of the source.static List<CacheUtil.CacheId> getCacheIds(String filter, boolean jnlpPath, boolean domain) This method load all known IDs of applications and will gather all members, which share the idstatic StringgetCacheParentDirectory(String filePath) Returns the parent directory of the cached resource.static OutputStreamgetOutputStream(URL source, Version version) Returns a buffered output stream open for writing to the cache file.static PermissiongetReadPermission(URL location, Version version) Returns the Permission object necessary to access the resource, ornullif no permission is needed.static Stringstatic booleanisCacheable(URL source, Version version) Returns whether the resource can be cached as a local file; if not, then URLConnection.openStream can be used to obtain the contents.static booleanReturns true if the cache has a local copy of the contents of the URL matching the specified version string.static booleanisCurrent(URL source, Version version, long lastModifed, CacheEntry entry, File cachedFile) Returns whether there is a version of the URL contents in the cache and it is up to date.static voidlistCacheIds(String filter, boolean jnlpPath, boolean domain) static FilemakeNewCacheFile(URL source, Version version) This will create a new entry for the cache item.static voidremoveWindowsShortcuts(String jnlpApp) static voidstreamCopy(InputStream is, OutputStream os) Copies from an input stream to an output stream.static FileConverts a URL into a local path string within the given directory.static voidwaitForResources(ApplicationInstance app, ResourceTracker tracker, URL[] resources, String title) Waits until the resources are downloaded, while showing a progress indicator.
-
Constructor Details
-
CacheUtil
public CacheUtil()
-
-
Method Details
-
getCachedResourceURL
Caches a resource and returns a URL for it in the cache; blocks until resource is cached. If the resource location is not cacheable (points to a local file, etc) then the original URL is returned.- Parameters:
location- location of the resourceversion- the version, ornullpolicy- how to handle update- Returns:
- either the location in the cache or the original location
-
getCachedResourceFile
This is returning File object of cached resource originally from URL- Parameters:
location- original location of blobversion- version of resourcepolicy- update policy of resource- Returns:
- location in ITW cache on filesystem
-
getReadPermission
Returns the Permission object necessary to access the resource, ornullif no permission is needed.- Parameters:
location- location of the resourceversion- the version, ornull- Returns:
- permissions of the location
-
clearCache
public static boolean clearCache()Clears the cache by deleting all the Netx cache files Note: Because of how our caching system works, deleting jars of another javaws process is using them can be quite disasterous. Hence why Launcher creates lock files and we check for those by callingokToClearCache()- Returns:
- true if the cache could be cleared and was cleared
-
clearCache
-
checkToClearCache
public static boolean checkToClearCache() -
removeWindowsShortcuts
- Throws:
IOException
-
listCacheIds
-
getCacheIds
This method load all known IDs of applications and will gather all members, which share the id- Parameters:
filter- - regex to filter keys- Returns:
-
isCurrent
public static boolean isCurrent(URL source, Version version, long lastModifed, CacheEntry entry, File cachedFile) Returns whether there is a version of the URL contents in the cache and it is up to date. This method may not return immediately.- Parameters:
source- the sourceURLversion- the versions to check forlastModifed- time in milis since epoch of last modfication- Returns:
- whether the cache contains the version
- Throws:
IllegalArgumentException- if the source is not cacheable
-
isCached
Returns true if the cache has a local copy of the contents of the URL matching the specified version string.- Parameters:
source- the source URLversion- the versions to check for- Returns:
- true if the source is in the cache
- Throws:
IllegalArgumentException- if the source is not cacheable
-
isCacheable
Returns whether the resource can be cached as a local file; if not, then URLConnection.openStream can be used to obtain the contents.- Parameters:
source- the url of resourceversion- version of resource- Returns:
- whether this resource can be cached
-
getCacheFile
Returns the file for the locally cached contents of the source. This method returns the file location only and does not download the resource. The latest version of the resource that matches the specified version will be returned.- Parameters:
source- the sourceURLversion- the version id of the local file- Returns:
- the file location in the cache, or
nullif no versions cached - Throws:
IllegalArgumentException- if the source is not cacheable
-
getCacheParentDirectory
Returns the parent directory of the cached resource.- Parameters:
filePath- The path of the cached resource directory.- Returns:
- parent dir of cache
-
makeNewCacheFile
This will create a new entry for the cache item. It is however not initialized but any future calls to getCacheFile with the source and version given to here, will cause it to return this item.- Parameters:
source- the source URLversion- the version id of the local file- Returns:
- the file location in the cache.
-
getOutputStream
Returns a buffered output stream open for writing to the cache file.- Parameters:
source- the remote locationversion- the file version to write to- Returns:
- the stream to write to resource
- Throws:
IOException- if IO breaks
-
streamCopy
Copies from an input stream to an output stream. On completion, both streams will be closed. Streams are buffered automatically.- Parameters:
is- stream to read fromos- stream to write to- Throws:
IOException- if copy fails
-
urlToPath
Converts a URL into a local path string within the given directory. For example a url with subdirectory /tmp/ will result in a File that is located somewhere within /tmp/- Parameters:
location- the urlsubdir- the subdirectory- Returns:
- the file
-
hex
- Throws:
NoSuchAlgorithmException
-
waitForResources
public static void waitForResources(ApplicationInstance app, ResourceTracker tracker, URL[] resources, String title) Waits until the resources are downloaded, while showing a progress indicator.- Parameters:
app- application instance with context for this resourcetracker- the resource trackerresources- the resources to wait fortitle- name of the download
-
cleanCache
public static void cleanCache()This will remove all old cache items.
-