CacheUtil (IcedTea-Web: NetX )
Keywords: net.sourceforge.jnlp.cache.CacheUtil class
Date: 2021-03-21

net.sourceforge.jnlp.cache

## Class CacheUtil

- java.lang.Object
- - net.sourceforge.jnlp.cache.CacheUtil

-     public class CacheUtil
      extends java.lang.Object

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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `CacheUtil.CacheId`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CacheUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `checkToClearCache()`
    `static void` | `cleanCache()` This will remove all old cache items.
    `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.
    `static boolean` | `clearCache(java.lang.String application, boolean jnlpPath, boolean domain)`
    `static java.io.File` | `getCachedResourceFile(java.net.URL location, Version version, UpdatePolicy policy)` This is returning File object of cached resource originally from URL
    `static java.net.URL` | `getCachedResourceURL(java.net.URL location, Version version, UpdatePolicy policy)` Caches a resource and returns a URL for it in the cache; blocks until resource is cached.
    `static java.io.File` | `getCacheFile(java.net.URL source, Version version)` Returns the file for the locally cached contents of the source.
    `static java.util.List<CacheUtil.CacheId>` | `getCacheIds(java.lang.String filter, boolean jnlpPath, boolean domain)` This method load all known IDs of applications and will gather all members, which share the id
    `static java.lang.String` | `getCacheParentDirectory(java.lang.String filePath)` Returns the parent directory of the cached resource.
    `static java.io.OutputStream` | `getOutputStream(java.net.URL source, Version version)` Returns a buffered output stream open for writing to the cache file.
    `static java.security.Permission` | `getReadPermission(java.net.URL location, Version version)` Returns the Permission object necessary to access the resource, or `null` if no permission is needed.
    `static java.lang.String` | `hex(java.lang.String origName, java.lang.String candidate)`
    `static boolean` | `isCacheable(java.net.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(java.net.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(java.net.URL source, Version version, long lastModifed, CacheEntry entry, java.io.File cachedFile)` Returns whether there is a version of the URL contents in the cache and it is up to date.
    `static void` | `listCacheIds(java.lang.String filter, boolean jnlpPath, boolean domain)`
    `static java.io.File` | `makeNewCacheFile(java.net.URL source, Version version)` This will create a new entry for the cache item.
    `static void` | `removeWindowsShortcuts(java.lang.String jnlpApp)`
    `static void` | `streamCopy(java.io.InputStream is, java.io.OutputStream os)` Copies from an input stream to an output stream.
    `static java.io.File` | `urlToPath(java.net.URL location, java.lang.String subdir)` Converts a URL into a local path string within the given directory.
    `static void` | `waitForResources(ApplicationInstance app, ResourceTracker tracker, java.net.URL[] resources, java.lang.String title)` Waits until the resources are downloaded, while showing a progress indicator.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CacheUtil

          public CacheUtil()

  - ### Method Detail

    - #### getCachedResourceURL

          public static java.net.URL getCachedResourceURL(java.net.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`
        `policy` - how to handle update
      Returns:
        either the location in the cache or the original location

    - #### getCachedResourceFile

          public static java.io.File getCachedResourceFile(java.net.URL location,
                                                           Version version,
                                                           UpdatePolicy policy)

      This is returning File object of cached resource originally from URL
      Parameters:
        `location` - original location of blob
        `version` - version of resource
        `policy` - update policy of resource
      Returns:
        location in ITW cache on filesystem

    - #### getReadPermission

          public static java.security.Permission getReadPermission(java.net.URL location,
                                                                   Version version)

      Returns the Permission object necessary to access the resource, or `null` if no permission is needed.
      Parameters:
        `location` - location of the resource
        `version` - the version, or `null`
      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 calling `okToClearCache()`
      Returns:
        true if the cache could be cleared and was cleared

    - #### clearCache

          public static boolean clearCache(java.lang.String application,
                                           boolean jnlpPath,
                                           boolean domain)

    - #### checkToClearCache

          public static boolean checkToClearCache()

    - #### removeWindowsShortcuts

          public static void removeWindowsShortcuts(java.lang.String jnlpApp)
                                             throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### listCacheIds

          public static void listCacheIds(java.lang.String filter,
                                          boolean jnlpPath,
                                          boolean domain)

    - #### getCacheIds

          public static java.util.List<CacheUtil.CacheId> getCacheIds(java.lang.String filter,
                                                                      boolean jnlpPath,
                                                                      boolean domain)

      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(java.net.URL source,
                                          Version version,
                                          long lastModifed,
                                          CacheEntry entry,
                                          java.io.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 source `URL`
        `version` - the versions to check for
        `lastModifed` - time in milis since epoch of last modfication
      Returns:
        whether the cache contains the version
      Throws:
        `java.lang.IllegalArgumentException` - if the source is not cacheable

    - #### isCached

          public static boolean isCached(java.net.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
      Throws:
        `java.lang.IllegalArgumentException` - if the source is not cacheable

    - #### isCacheable

          public static boolean isCacheable(java.net.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.
      Parameters:
        `source` - the url of resource
        `version` - version of resource
      Returns:
        whether this resource can be cached

    - #### getCacheFile

          public static java.io.File getCacheFile(java.net.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
      Throws:
        `java.lang.IllegalArgumentException` - if the source is not cacheable

    - #### getCacheParentDirectory

          public static java.lang.String getCacheParentDirectory(java.lang.String filePath)

      Returns the parent directory of the cached resource.
      Parameters:
        `filePath` - The path of the cached resource directory.
      Returns:
        parent dir of cache

    - #### makeNewCacheFile

          public static java.io.File makeNewCacheFile(java.net.URL source,
                                                      Version version)

      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 URL
        `version` - the version id of the local file
      Returns:
        the file location in the cache.

    - #### getOutputStream

          public static java.io.OutputStream getOutputStream(java.net.URL source,
                                                             Version version)
                                                      throws java.io.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
      Returns:
        the stream to write to resource
      Throws:
        `java.io.IOException` - if IO breaks

    - #### streamCopy

          public static void streamCopy(java.io.InputStream is,
                                        java.io.OutputStream os)
                                 throws java.io.IOException

      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 from
        `os` - stream to write to
      Throws:
        `java.io.IOException` - if copy fails

    - #### urlToPath

          public static java.io.File urlToPath(java.net.URL location,
                                               java.lang.String subdir)

      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 url
        `subdir` - the subdirectory
      Returns:
        the file

    - #### hex

          public static java.lang.String hex(java.lang.String origName,
                                             java.lang.String candidate)
                                      throws java.security.NoSuchAlgorithmException

      Throws:
        `java.security.NoSuchAlgorithmException`

    - #### waitForResources

          public static void waitForResources(ApplicationInstance app,
                                              ResourceTracker tracker,
                                              java.net.URL[] resources,
                                              java.lang.String title)

      Waits until the resources are downloaded, while showing a progress indicator.
      Parameters:
        `app` - application instance with context for this resource
        `tracker` - the resource tracker
        `resources` - the resources to wait for
        `title` - name of the download

    - #### cleanCache

          public static void cleanCache()

      This will remove all old cache items.

Submit a bug or feature