netx.jnlp.cache

Class CacheUtil


public class CacheUtil
extends java.lang.Object

Provides static methods to interact with the cache, download indicator, and other utility methods.

Version:
$Revision: 1.17 $
Author:
Jon A. Maxwell (JAM) - initial author

Method Summary

static File
getCacheFile(URL source, Version version)
Returns the file for the locally cached contents of the source.
static URL
getCachedResource(URL location, Version version, UpdatePolicy policy)
Caches a resource and returns a URL for it in the cache; blocks until resource is cached.
static OutputStream
getOutputStream(URL source, Version version)
Returns a buffered output stream open for writing to the cache file.
static Permission
getReadPermission(URL location, Version version)
Returns the Permission object necessary to access the resource, or null if no permission is needed.
static boolean
isCacheable(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 boolean
isCached(URL source, Version version)
Returns true if the cache has a local copy of the contents of the URL matching the specified version string.
static boolean
isCurrent(URL source, Version version, URLConnection connection)
Returns whether there is a version of the URL contents in the cache and it is up to date.
static void
streamCopy(InputStream is, OutputStream os)
Copies from an input stream to an output stream.
static boolean
urlEquals(URL u1, URL u2)
Compares a URL using string compare of its protocol, host, port, path, query, and anchor.
static File
urlToPath(URL location, String subdir)
Converts a URL into a local path string within the runtime's base directory.
static void
waitForResources(ApplicationInstance app, ResourceTracker tracker, resources[] , String title)
Waits until the resources are downloaded, while showing a progress indicator.

Method Details

getCacheFile

public static File getCacheFile(URL source,
                                Version version)
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 source URL
version - the version id of the local file
Returns:
the file location in the cache, or null if no versions cached

getCachedResource

public static URL getCachedResource(URL location,
                                    Version version,
                                    UpdatePolicy policy)
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 resource
version - the version, or null
Returns:
either the location in the cache or the original location

getOutputStream

public static OutputStream getOutputStream(URL source,
                                           Version version)
            throws IOException
Returns a buffered output stream open for writing to the cache file.
Parameters:
source - the remote location
version - the file version to write to

getReadPermission

public static Permission getReadPermission(URL location,
                                           Version version)
Returns the Permission object necessary to access the resource, or null if no permission is needed.

isCacheable

public static boolean isCacheable(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.

isCached

public static boolean isCached(URL source,
                               Version version)
Returns true if the cache has a local copy of the contents of the URL matching the specified version string.
Parameters:
source - the source URL
version - the versions to check for
Returns:
true if the source is in the cache

isCurrent

public static boolean isCurrent(URL source,
                                Version version,
                                URLConnection connection)
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 source URL
version - the versions to check for
connection - a connection to the URL, or null
Returns:
whether the cache contains the version

streamCopy

public static void streamCopy(InputStream is,
                              OutputStream os)
            throws IOException
Copies from an input stream to an output stream. On completion, both streams will be closed. Streams are buffered automatically.

urlEquals

public static boolean urlEquals(URL u1,
                                URL u2)
Compares a URL using string compare of its protocol, host, port, path, query, and anchor. This method avoids the host name lookup that URL.equals does for http: protocol URLs. It may not return the same value as the URL.equals method (different hostnames that resolve to the same IP address, ie sourceforge.net and www.sourceforge.net).

urlToPath

public static File urlToPath(URL location,
                             String subdir)
Converts a URL into a local path string within the runtime's base directory.
Parameters:
location - the url
subdir - subdirectory under the base directory
Returns:
the file

waitForResources

public static void waitForResources(ApplicationInstance app,
                                    ResourceTracker tracker,
                                    resources[] ,
                                    String title)
Waits until the resources are downloaded, while showing a progress indicator.
Parameters:
tracker - the resource tracker
title - name of the download