LimeWire Consolidated API

com.limegroup.gnutella.downloader
Class AbstractCoreDownloader

java.lang.Object
  extended by com.limegroup.gnutella.downloader.AbstractCoreDownloader
All Implemented Interfaces:
BandwidthTracker, Downloader, CoreDownloader, DownloaderInfo, ListenerSupport<DownloadStateEvent>
Direct Known Subclasses:
BTDownloaderImpl, BTTorrentFileDownloaderImpl, MozillaDownloaderImpl

public abstract class AbstractCoreDownloader
extends Object
implements CoreDownloader

A basic implementation of CoreDownloader. Subclasses still need to do the heavy-lifting.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.limegroup.gnutella.DownloaderInfo
DownloaderInfo.DownloadState
 
Field Summary
 
Fields inherited from interface com.limegroup.gnutella.Downloader
BITTORRENT_DOWNLOAD, CUSTOM_INACTIVITY_KEY
 
Constructor Summary
protected AbstractCoreDownloader(SaveLocationManager saveLocationManager)
           
 
Method Summary
 boolean conflictsSaveFile(File saveFile)
           
protected abstract  DownloadMemento createMemento()
          Constructs the correct type of memento.
protected  void fillInMemento(DownloadMemento memento)
          Fills in all data this class wants to store.
 Object getAttribute(String key)
          Gets a value of attribute associated with the download.
protected  String getDefaultFileName()
          Returns the value for the key CoreDownloader#DEFAULT_FILENAME from the properties map.
protected abstract  File getDefaultSaveFile()
          A default location where this file should be saved, if no explicit saveFile is set.
 int getInactivePriority()
          Returns the inactive priority of this download.
 File getSaveFile()
          Returns the file under which the download will be saved when complete.
protected  boolean hasDefaultFileName()
          Returns true if a defaultFileName is set.
 void initFromMemento(DownloadMemento memento)
          Initializes this object from the given memento.
 boolean isMementoSupported()
          Indicator of whether this downloader supports a memento or not.
 Object removeAttribute(String key)
          Removes an attribute associated with this download.
 Object setAttribute(String key, Object value, boolean serialize)
          Sets a new attribute associated with the download.
protected  void setDefaultFileName(String defaultFileName)
          Sets the default filename this will use.
 void setInactivePriority(int priority)
          Sets the inactive priority of this download.
 void setSaveFile(File saveDirectory, String fileName, boolean overwrite)
          Sets the directory where the file will be saved.
 DownloadMemento toMemento()
          Constructs a memento that will be used for serialization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.limegroup.gnutella.downloader.CoreDownloader
conflicts, conflictsWithIncompleteFile, finish, getDownloadType, getQueryGUID, handleInactivity, initialize, isAlive, isQueuable, shouldBeRemoved, shouldBeRestarted, startDownload
 
Methods inherited from interface com.limegroup.gnutella.Downloader
deleteIncompleteFiles, discardCorruptDownload, getAmountLost, getAmountPending, getAmountVerified, getBrowseEnabledHost, getBusyHostCount, getChunkSize, getCustomIconDescriptor, getDownloadFragment, getFile, getNumberOfAlternateLocations, getNumberOfInvalidAlternateLocations, getNumHosts, getPossibleHostCount, getQueuedHostCount, getQueuePosition, getRemainingStateTime, getSha1Urn, getSourcesAsAddresses, getTriedHostCount, getVendor, hasBrowseEnabledHost, isInactive, isLaunchable, isPausable, isPaused, isRelocatable, isResumable, pause, resume, stop
 
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
 

Constructor Detail

AbstractCoreDownloader

protected AbstractCoreDownloader(SaveLocationManager saveLocationManager)
Method Detail

setInactivePriority

public void setInactivePriority(int priority)
Description copied from interface: CoreDownloader
Sets the inactive priority of this download.

Specified by:
setInactivePriority in interface CoreDownloader

getInactivePriority

public int getInactivePriority()
Description copied from interface: Downloader
Returns the inactive priority of this download.

Specified by:
getInactivePriority in interface Downloader

setAttribute

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

Specified by:
setAttribute in interface Downloader
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

public Object getAttribute(String key)
Description copied from interface: Downloader
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.

Specified by:
getAttribute in interface Downloader
Parameters:
key - A key which identifies the attribute.
Returns:
The value of the specified attribute, or null if value was not specified.

removeAttribute

public Object removeAttribute(String key)
Description copied from interface: Downloader
Removes an attribute associated with this download.

Specified by:
removeAttribute in interface Downloader
Parameters:
key - A key which identifies the attribute do remove.
Returns:
A value of the attribute or null if attribute was not set.

conflictsSaveFile

public boolean conflictsSaveFile(File saveFile)
Specified by:
conflictsSaveFile in interface CoreDownloader

setSaveFile

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

Specified by:
setSaveFile in interface Downloader
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

public File getSaveFile()
Description copied from interface: Downloader
Returns the file under which the download will be saved when complete. Counterpart to setSaveFile.

Specified by:
getSaveFile in interface Downloader

getDefaultSaveFile

protected abstract File getDefaultSaveFile()
A default location where this file should be saved, if no explicit saveFile is set.


getDefaultFileName

protected String getDefaultFileName()
Returns the value for the key CoreDownloader#DEFAULT_FILENAME from the properties map.

Subclasses should put the name into the map or override this method.


hasDefaultFileName

protected boolean hasDefaultFileName()
Returns true if a defaultFileName is set.


setDefaultFileName

protected void setDefaultFileName(String defaultFileName)
Sets the default filename this will use.


initFromMemento

public void initFromMemento(DownloadMemento memento)
                     throws InvalidDataException
Description copied from interface: CoreDownloader
Initializes this object from the given memento.

Specified by:
initFromMemento in interface CoreDownloader
Throws:
InvalidDataException - if the memento contains invalid data.

toMemento

public final DownloadMemento toMemento()
Description copied from interface: CoreDownloader
Constructs a memento that will be used for serialization.

Specified by:
toMemento in interface CoreDownloader

createMemento

protected abstract DownloadMemento createMemento()
Constructs the correct type of memento.


fillInMemento

protected void fillInMemento(DownloadMemento memento)
Fills in all data this class wants to store.


isMementoSupported

public boolean isMementoSupported()
Description copied from interface: CoreDownloader
Indicator of whether this downloader supports a memento or not.

Specified by:
isMementoSupported in interface CoreDownloader

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.