Package net.sourceforge.jnlp.cache
Class Resource
java.lang.Object
net.sourceforge.jnlp.cache.Resource
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.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoid
addTracker
(ResourceTracker tracker) Adds the tracker to the list of trackers monitoring this resource.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.boolean
protected void
Instructs the trackers monitoring this resource to fire a download event.Returns the URL to use for downloading the resource.Returns the remote location of the resource.static Resource
getResource
(URL location, Version requestVersion, UpdatePolicy updatePolicy) Return a shared Resource object representing the given location and version.long
getSize()
Returns the size of the resourcelong
boolean
hasFlags
(Collection<Resource.Status> flags) Check if all the specified flags are set.int
hashCode()
void
incrementTransferred
(long incTrans) Increments the amount transferred (in bytes)boolean
boolean
Check if this resource has been initializedboolean
isSet
(Resource.Status flag) Check if the specified flag is set.void
removeTracker
(ResourceTracker tracker) Removes the tracker to the list of trackers monitoring this resource.void
Clear all flagsvoid
setDownloadLocation
(URL downloadLocation) Set the url to use for downloading the resourcevoid
setDownloadOptions
(DownloadOptions downloadOptions) void
setDownloadVersion
(Version downloadVersion) Sets the version downloaded from servervoid
setLocalFile
(File localFile) Sets the local file to be downloadedvoid
setSize
(long size) Sets the size of the resourcevoid
setStatusFlag
(Resource.Status flag) Set status flagvoid
setStatusFlags
(Collection<Resource.Status> flags) Set flagsvoid
setTransferred
(long transferred) Sets the amount transferredtoString()
void
unsetStatusFlag
(Collection<Resource.Status> flags) Unset flags
-
Method Details
-
getResource
Return a shared Resource object representing the given location and version.- Parameters:
location
- final location of resourcerequestVersion
- final version of resourceupdatePolicy
- final policy for updating- Returns:
- new resource, which is already added in resources list
-
getLocation
Returns the remote location of the resource.- Returns:
- the same location as the one with which this resource was created
-
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
Set the url to use for downloading the resource- Parameters:
downloadLocation
- url to be donloaded
-
getLocalFile
- Returns:
- the local file currently being downloaded
-
setLocalFile
Sets the local file to be downloaded- Parameters:
localFile
- location of stored resource
-
getRequestVersion
- Returns:
- the requested version
-
getDownloadVersion
- Returns:
- the version downloaded from server
-
setDownloadVersion
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
- Returns:
- the status of the resource
-
isSet
Check if the specified flag is set.- Parameters:
flag
- a status flag- Returns:
- true iff the flag is set
-
hasFlags
Check if all the specified flags are set.- Parameters:
flags
- a collection of flags- Returns:
- true iff all the flags are set
-
getUpdatePolicy
- Returns:
- the update policy for this resource
-
changeStatus
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 unsetadd
- a collection of status flags to set
-
setStatusFlag
Set status flag- Parameters:
flag
- a flag to set
-
setStatusFlags
Set flags- Parameters:
flags
- a collection of flags to set
-
unsetStatusFlag
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
Removes the tracker to the list of trackers monitoring this resource.- Parameters:
tracker
- tracker to be removed
-
addTracker
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
-
getDownloadOptions
-
isConnectable
public boolean isConnectable() -
hashCode
public int hashCode() -
equals
-
toString
-