public class FetchAndAdd extends Snark implements EepGet.StatusListener, Runnable
Upon successful download, this Snark will be deleted and a "real" Snark created.
The methods return values similar to a Snark in magnet mode. A fake info hash, which is the SHA1 of the URL, is returned to prevent duplicates.
This Snark may be stopped and restarted, although a partially downloaded file is discarded.
_util, PROP_MAX_CONNECTIONS, storageCompleted| Constructor and Description |
|---|
FetchAndAdd(I2PAppContext ctx,
SnarkManager mgr,
String url,
File dataDir)Caller should call _mgr.addDownloader(this), which will start things off. |
| Modifier and Type | Method and Description |
|---|---|
void | attemptFailed(String url,
long bytesTransferred,
long bytesRemaining,
int currentAttempt,
int numRetries,
Exception cause)Called when a download attempt fails. |
void | attempting(String url)Called when a download attempt is starting. |
void | bytesTransferred(long alreadyTransferred,
int currentWrite,
long bytesTransferred,
long bytesRemaining,
String url)Called when bytes are transferred during download. |
String | getBaseName()Get the base name of the torrent. |
long | getDownloaded()Get the total number of bytes downloaded. |
long | getDownloadRate()Get the current download rate in bytes per second. |
byte[] | getInfoHash()Get the info hash. |
String | getName()Get the file name of the .torrent file. |
long | getNeededLength()Bytes still wanted. |
int | getPeerCount()Get the peer count. |
long | getRemainingLength()Bytes not yet in storage. |
long | getTotalLength()Get the total length of all torrent files. |
int | getTrackerSeenPeers()Get the tracker seen peers count. |
void | headerReceived(String url,
int attemptNum,
String key,
String val)Called when an HTTP header is received. |
boolean | isStopped()Check if the torrent is stopped. |
void | run()Set off by startTorrent(). |
void | startTorrent()Start up contacting peers and querying the tracker. |
void | stopTorrent()Stop contacting the tracker and talking with peers |
void | transferComplete(long alreadyTransferred,
long bytesTransferred,
long bytesRemaining,
String url,
String outputFile,
boolean notModified)Called when a transfer completes successfully. |
void | transferFailed(String url,
long bytesTransferred,
long bytesRemaining,
int currentAttempt)Called when a transfer fails. |
addComments, addMessage, getCheckingProgress, getComments, getID, getMetaInfo, getNeeded, getPeerList, getPieceLength, getPieces, getRPCID, getSkippedLength, getStartedTime, getStorage, getTrackerProblems, getTrackerURL, getUploaded, getUploadRate, gotMetaInfo, isAllocating, isAutoStoppable, isChecking, isNotificationSent, isStarting, isStorageCompleted, overUploadLimit, peerChange, replaceMetaInfo, restartAcceptor, setAutoStoppable, setNotificationSent, setStarting, setTrackerProblems, setTrackerSeenPeers, setWantedPieces, shutdown, stopTorrent, storageAllChecked, storageAllocated, storageChecked, storageCompleted, storageCreateFile, updatePiecePrioritiespublic FetchAndAdd(I2PAppContext ctx, SnarkManager mgr, String url, File dataDir)
dataDir - null to default to snark data directoryctx - the ctxpublic void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause)
attemptFailed in interface EepGet.StatusListenerurl - the URL being downloadedbytesTransferred - bytes transferred so farbytesRemaining - bytes remaining to transfercurrentAttempt - the current attempt numbernumRetries - the maximum number of retriescause - the exception that caused the failure, or nullEepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)public void attempting(String url)
attempting in interface EepGet.StatusListenerurl - the URL being downloadedpublic void bytesTransferred(long alreadyTransferred,
int currentWrite,
long bytesTransferred,
long bytesRemaining,
String url)bytesTransferred in interface EepGet.StatusListeneralreadyTransferred - total bytes transferred before this writecurrentWrite - number of bytes in this writebytesTransferred - total bytes transferred so farbytesRemaining - bytes remaining to transferurl - the URL being downloadedpublic String getBaseName()
SnarkgetBaseName in class Snarkpublic long getDownloaded()
SnarkgetDownloaded in class Snarkpublic long getDownloadRate()
SnarkgetDownloadRate in class Snarkpublic byte[] getInfoHash()
SnarkgetInfoHash in class Snarkpublic String getName()
Snarkpublic long getNeededLength()
SnarkgetNeededLength in class Snarkpublic int getPeerCount()
SnarkgetPeerCount in class Snarkpublic long getRemainingLength()
SnarkgetRemainingLength in class Snarkpublic long getTotalLength()
SnarkgetTotalLength in class Snarkpublic int getTrackerSeenPeers()
SnarkgetTrackerSeenPeers in class Snarkpublic void headerReceived(String url, int attemptNum, String key, String val)
headerReceived in interface EepGet.StatusListenerurl - the URL being downloadedattemptNum - the current attempt numberkey - the header nameval - the header valuepublic boolean isStopped()
Snarkpublic void startTorrent()
SnarkstartTorrent in class Snarkpublic void stopTorrent()
SnarkstopTorrent in class Snarkpublic void transferComplete(long alreadyTransferred,
long bytesTransferred,
long bytesRemaining,
String url,
String outputFile,
boolean notModified)transferComplete in interface EepGet.StatusListeneralreadyTransferred - total bytes transferred before this callbytesTransferred - bytes transferred in this callbytesRemaining - bytes remaining (should be 0)url - the URL being downloadedoutputFile - the output file pathnotModified - true if the server returned 304EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt)
transferFailed in interface EepGet.StatusListenerurl - the URL being downloadedbytesTransferred - bytes transferred so farbytesRemaining - bytes remaining to transfercurrentAttempt - the current attempt numberEepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)