Class Resource

java.lang.Object
net.sourceforge.jnlp.cache.Resource

public class Resource extends Object

Information about a single resource to download. This class tracks the downloading of various resources of a JNLP file to local files. It can be used to download icons, jnlp and extension files, jars, and jardiff files using the version based protocol or any file using the basic download protocol.

Resources can be put into download groups by specifying a part name for the resource. The resource tracker can also be configured to prefetch resources, which are downloaded in the order added to the media tracker.

  • Method Details

    • getResource

      public static Resource getResource(URL location, Version requestVersion, UpdatePolicy updatePolicy)
      Return a shared Resource object representing the given location and version.
      Parameters:
      location - final location of resource
      requestVersion - final version of resource
      updatePolicy - final policy for updating
      Returns:
      new resource, which is already added in resources list
    • getLocation

      public URL getLocation()
      Returns the remote location of the resource.
      Returns:
      the same location as the one with which this resource was created
    • getDownloadLocation

      public URL getDownloadLocation()
      Returns the URL to use for downloading the resource. This can be different from the original location since it may use a different file name to support versioning and compression
      Returns:
      the url to use when downloading
    • setDownloadLocation

      public void setDownloadLocation(URL downloadLocation)
      Set the url to use for downloading the resource
      Parameters:
      downloadLocation - url to be donloaded
    • getLocalFile

      public File getLocalFile()
      Returns:
      the local file currently being downloaded
    • setLocalFile

      public void setLocalFile(File localFile)
      Sets the local file to be downloaded
      Parameters:
      localFile - location of stored resource
    • getRequestVersion

      public Version getRequestVersion()
      Returns:
      the requested version
    • getDownloadVersion

      public Version getDownloadVersion()
      Returns:
      the version downloaded from server
    • setDownloadVersion

      public void setDownloadVersion(Version downloadVersion)
      Sets the version downloaded from server
      Parameters:
      downloadVersion - version of downloaded resource
    • getTransferred

      public long getTransferred()
      Returns:
      the amount in bytes transferred
    • setTransferred

      public void setTransferred(long transferred)
      Sets the amount transferred
      Parameters:
      transferred - set the whole transfered amount to this value
    • incrementTransferred

      public void incrementTransferred(long incTrans)
      Increments the amount transferred (in bytes)
      Parameters:
      incTrans - transfered amount in last transfer
    • getSize

      public long getSize()
      Returns the size of the resource
      Returns:
      size of resource (-1 if unknown)
    • setSize

      public void setSize(long size)
      Sets the size of the resource
      Parameters:
      size - desired size of resource
    • getCopyOfStatus

      public Set<Resource.Status> getCopyOfStatus()
      Returns:
      the status of the resource
    • isSet

      public boolean isSet(Resource.Status flag)
      Check if the specified flag is set.
      Parameters:
      flag - a status flag
      Returns:
      true iff the flag is set
    • hasFlags

      public boolean hasFlags(Collection<Resource.Status> flags)
      Check if all the specified flags are set.
      Parameters:
      flags - a collection of flags
      Returns:
      true iff all the flags are set
    • getUpdatePolicy

      public UpdatePolicy getUpdatePolicy()
      Returns:
      the update policy for this resource
    • changeStatus

      public void changeStatus(Collection<Resource.Status> clear, Collection<Resource.Status> add)
      Changes the status by clearing the flags in the first parameter and setting the flags in the second. This method is synchronized on this resource.
      Parameters:
      clear - a collection of status flags to unset
      add - a collection of status flags to set
    • setStatusFlag

      public void setStatusFlag(Resource.Status flag)
      Set status flag
      Parameters:
      flag - a flag to set
    • setStatusFlags

      public void setStatusFlags(Collection<Resource.Status> flags)
      Set flags
      Parameters:
      flags - a collection of flags to set
    • unsetStatusFlag

      public void unsetStatusFlag(Collection<Resource.Status> flags)
      Unset flags
      Parameters:
      flags - a collection of flags to unset
    • resetStatus

      public void resetStatus()
      Clear all flags
    • isInitialized

      public boolean isInitialized()
      Check if this resource has been initialized
      Returns:
      true iff any flags have been set
    • removeTracker

      public void removeTracker(ResourceTracker tracker)
      Removes the tracker to the list of trackers monitoring this resource.
      Parameters:
      tracker - tracker to be removed
    • addTracker

      public void addTracker(ResourceTracker tracker)
      Adds the tracker to the list of trackers monitoring this resource.
      Parameters:
      tracker - to observing resource
    • fireDownloadEvent

      protected void fireDownloadEvent()
      Instructs the trackers monitoring this resource to fire a download event.
    • setDownloadOptions

      public void setDownloadOptions(DownloadOptions downloadOptions)
    • getDownloadOptions

      public DownloadOptions getDownloadOptions()
    • isConnectable

      public boolean isConnectable()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object