LimeWire Consolidated API

com.limegroup.gnutella
Interface Downloader

All Superinterfaces:
BandwidthTracker, DownloaderInfo, ListenerSupport<DownloadStateEvent>
All Known Subinterfaces:
BTDownloader, BTTorrentFileDownloader, CoreDownloader, InNetworkDownloader, MagnetDownloader, ManagedDownloader, ResumeDownloader, StoreDownloader
All Known Implementing Classes:
AbstractCoreDownloader, BTDownloaderImpl, BTTorrentFileDownloaderImpl, MozillaDownloaderImpl

public interface Downloader
extends DownloaderInfo, BandwidthTracker, ListenerSupport<DownloadStateEvent>

Defines an interface for downloading a file. The user interface maintains a list of Downloader's and uses its methods to stop and resume downloads. Note that there is no start method; it is assumed that the downloader will start as soon as it is instantiated.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.limegroup.gnutella.DownloaderInfo
DownloaderInfo.DownloadState
 
Field Summary
static String BITTORRENT_DOWNLOAD
          Marker string for BitTorrent downloads.
static String CUSTOM_INACTIVITY_KEY
          Key for custom description of the inactivity state.
 
Method Summary
 void deleteIncompleteFiles()
          Deletes the incomplete files for this downloader.
 void discardCorruptDownload(boolean delete)
          Either treats a corrupt file as normal file and saves it, or discards the corruptFile, depending on the value of delete.
 long getAmountLost()
           
 int getAmountPending()
           
 long getAmountVerified()
           
 Object getAttribute(String key)
          Gets a value of attribute associated with the download.
 RemoteFileDesc getBrowseEnabledHost()
          Returns a browse-enabled RemoteFileDesc instance for this Downloader.
 int getBusyHostCount()
           
 int getChunkSize()
           
 String getCustomIconDescriptor()
           
 File getDownloadFragment()
          If this download is not yet complete, returns a copy of the first contiguous fragment of the incomplete file.
 File getFile()
          Returns the file that this downloader is using.
 int getInactivePriority()
          Returns the inactive priority of this download.
 int getNumberOfAlternateLocations()
          Return the number of validated alternate locations for this download.
 int getNumberOfInvalidAlternateLocations()
          Return the number of invalid alternate locations for this download.
 int getNumHosts()
           
 int getPossibleHostCount()
           
 int getQueuedHostCount()
           
 int getQueuePosition()
          Returns the position of the download on the uploader, relevant only if the downloader is queued.
 int getRemainingStateTime()
          Returns an upper bound on the amount of time (in seconds) this will stay in the current state.
 File getSaveFile()
          Returns the file under which the download will be saved when complete.
 URN getSha1Urn()
          Returns the sha1 urn associated with the file being downloaded, or null if there is none.
 List<Address> getSourcesAsAddresses()
          Gets all sources as addresses
 int getTriedHostCount()
          Returns the number of hosts that were attempted to connect to.
 String getVendor()
          Returns the vendor of the last downloading host.
 boolean hasBrowseEnabledHost()
          Returns whether or not there is a browse-enabled host available for this Downloader.
 boolean isInactive()
          Determines if this downloader is in an inactive state
 boolean isLaunchable()
           
 boolean isPausable()
           
 boolean isPaused()
          Determines if this download is paused or not.
 boolean isRelocatable()
          Determines if this can have its saveLocation changed.
 boolean isResumable()
           
 void pause()
          Pauses this download.
 Object removeAttribute(String key)
          Removes an attribute associated with this download.
 boolean resume()
          Resumes this.
 Object setAttribute(String key, Object value, boolean serialize)
          Sets a new attribute associated with the download.
 void setSaveFile(File saveDirectory, String fileName, boolean overwrite)
          Sets the directory where the file will be saved.
 void stop()
          Stops this download if it is not already stopped.
 
Methods inherited from interface com.limegroup.gnutella.DownloaderInfo
getAmountRead, getContentLength, getState, isCompleted
 
Methods inherited from interface com.limegroup.gnutella.BandwidthTracker
getAverageBandwidth, getMeasuredBandwidth, measureBandwidth
 
Methods inherited from interface org.limewire.listener.ListenerSupport
addListener, removeListener
 

Field Detail

BITTORRENT_DOWNLOAD

static final String BITTORRENT_DOWNLOAD
Marker string for BitTorrent downloads.

See Also:
Constant Field Values

CUSTOM_INACTIVITY_KEY

static final String CUSTOM_INACTIVITY_KEY
Key for custom description of the inactivity state.

See Also:
Constant Field Values
Method Detail

stop

void stop()
Stops this download if it is not already stopped.


pause

void pause()
Pauses this download. If the download is already paused or stopped, does nothing.


isPaused

boolean isPaused()
Determines if this download is paused or not.


isPausable

boolean isPausable()
Returns:
if this downloader can be paused.

isResumable

boolean isResumable()
Returns:
if this downloader can be resumed.

isInactive

boolean isInactive()
Determines if this downloader is in an inactive state


isRelocatable

boolean isRelocatable()
Determines if this can have its saveLocation changed.


getInactivePriority

int getInactivePriority()
Returns the inactive priority of this download.


resume

boolean resume()
Resumes this. If the download is GAVE_UP, tries all locations again and

Returns:
true If WAITING_FOR_RETRY, forces the retry immediately and returns true if some other downloader is currently downloading the file, throws AlreadyDowloadingException. If WAITING_FOR_USER, then launches another query. Otherwise does nothing and returns false.

getFile

File getFile()
Returns the file that this downloader is using. This is useful for retrieving information from the file, such as the icon. This should NOT be used for playing the file; instead, use getDownloadFragment() for the reasons described in that method.


getDownloadFragment

File getDownloadFragment()
If this download is not yet complete, returns a copy of the first contiguous fragment of the incomplete file. (The copying helps prevent file locking problems.) Returns null if the download hasn't started or the copy failed. If the download is complete, returns the saved file.

Returns:
the copied file fragment, saved file, or null

setSaveFile

void setSaveFile(File saveDirectory,
                 String fileName,
                 boolean overwrite)
                 throws SaveLocationException
Sets the directory where the file will be saved. If saveDirectory is null, the default save directory will be used.

Parameters:
saveDirectory - the directory where the file should be saved. null indicates the default.
fileName - the name of the file to be saved in saveDirectory. null indicates the default.
overwrite - is true if saving should be allowed to overwrite existing files
Throws:
SaveLocationException - when the new file location could not be set

getSaveFile

File getSaveFile()
Returns the file under which the download will be saved when complete. Counterpart to setSaveFile.


getRemainingStateTime

int getRemainingStateTime()
Returns an upper bound on the amount of time (in seconds) this will stay in the current state. Returns Integer.MAX_VALUE if unknown.


getAmountPending

int getAmountPending()
Returns:
the amount of data pending to be written on disk (i.e. in cache, queue)

getNumHosts

int getNumHosts()
Returns:
the number locations from which this is currently downloading. The number of hosts returned is only meaningful in the DownloadState#DOWNLOADING state.

getVendor

String getVendor()
Returns the vendor of the last downloading host.


isLaunchable

boolean isLaunchable()
Returns:
if this downloader can be launched.

discardCorruptDownload

void discardCorruptDownload(boolean delete)
Either treats a corrupt file as normal file and saves it, or discards the corruptFile, depending on the value of delete.


getBrowseEnabledHost

RemoteFileDesc getBrowseEnabledHost()
Returns a browse-enabled RemoteFileDesc instance for this Downloader.


hasBrowseEnabledHost

boolean hasBrowseEnabledHost()
Returns whether or not there is a browse-enabled host available for this Downloader.

Returns:
true if there is a browse-enabled host for this Downloader, false otherwise

getQueuePosition

int getQueuePosition()
Returns the position of the download on the uploader, relevant only if the downloader is queued.


getNumberOfAlternateLocations

int getNumberOfAlternateLocations()
Return the number of validated alternate locations for this download.


getNumberOfInvalidAlternateLocations

int getNumberOfInvalidAlternateLocations()
Return the number of invalid alternate locations for this download.


getPossibleHostCount

int getPossibleHostCount()
Returns:
the number of possible hosts for this download

getBusyHostCount

int getBusyHostCount()
Returns:
the number of hosts we tried which were busy. We will try these later

getQueuedHostCount

int getQueuedHostCount()
Returns:
the number of hosts we are remotely queued on.

getTriedHostCount

int getTriedHostCount()
Returns the number of hosts that were attempted to connect to. Should be reset whenever the downloader returns to the DownloadState#CONNECTING state.

Returns:
-1 if downloader does not support it

getAmountVerified

long getAmountVerified()
Returns:
the amount of data that has been verified

getChunkSize

int getChunkSize()
Returns:
the chunk size for the given download

getAmountLost

long getAmountLost()
Returns:
the amount of data lost due to corruption

getSha1Urn

URN getSha1Urn()
Returns the sha1 urn associated with the file being downloaded, or null if there is none.

Returns:

setAttribute

Object setAttribute(String key,
                    Object value,
                    boolean serialize)
Sets a new attribute associated with the download. The attributes are used, for example, by GUI to store some extra information about the download.

Parameters:
key - A key used to identify the attribute.
value - The value of the key.
serialize - Whether the attribute should be serialized to disk.
Returns:
A previous value of the attribute, or null if the attribute wasn't set.

getAttribute

Object getAttribute(String key)
Gets a value of attribute associated with the download. The attributes are used, for example, by GUI to store some extra information about the download.

Parameters:
key - A key which identifies the attribute.
Returns:
The value of the specified attribute, or null if value was not specified.

removeAttribute

Object removeAttribute(String key)
Removes an attribute associated with this download.

Parameters:
key - A key which identifies the attribute do remove.
Returns:
A value of the attribute or null if attribute was not set.

getCustomIconDescriptor

String getCustomIconDescriptor()
Returns:
a custom icon descriptor, null if the file icon should be used.

getSourcesAsAddresses

List<Address> getSourcesAsAddresses()
Gets all sources as addresses


deleteIncompleteFiles

void deleteIncompleteFiles()
Deletes the incomplete files for this downloader. The downloader should handle the possibility of this method being called multiple times.


LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.