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) |
void |
attempting(String url) |
void |
bytesTransferred(long alreadyTransferred,
int currentWrite,
long bytesTransferred,
long bytesRemaining,
String url)
Total length should be == alreadyTransferred + currentWrite + bytesRemaining for all calls
|
String |
getBaseName() |
long |
getDownloaded()
Get the total number of bytes downloaded.
|
long |
getDownloadRate()
Get the current download rate in bytes per second.
|
byte[] |
getInfoHash() |
String |
getName() |
long |
getNeededLength()
Bytes still wanted.
|
int |
getPeerCount() |
long |
getRemainingLength()
Bytes not yet in storage.
|
long |
getTotalLength() |
int |
getTrackerSeenPeers() |
void |
headerReceived(String url,
int attemptNum,
String key,
String val)
Note: Headers are not processed, and this is not called, for most error response codes,
unless setWriteErrorToOutput() is called before fetch().
|
boolean |
isStopped() |
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) |
void |
transferFailed(String url,
long bytesTransferred,
long bytesRemaining,
int currentAttempt) |
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 directorypublic void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause)
attemptFailed in interface EepGet.StatusListenerEepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)public void attempting(String url)
attempting in interface EepGet.StatusListenerpublic void bytesTransferred(long alreadyTransferred,
int currentWrite,
long bytesTransferred,
long bytesRemaining,
String url)
EepGet.StatusListenerbytesTransferred in interface EepGet.StatusListeneralreadyTransferred - total of all attempts, not including currentWrite
If nonzero on the first call, a partial file of that length was found,
_and_ the server supports resume.
If zero on a subsequent call after some bytes are transferred
(and presumably after an attemptFailed), the server does _not_
support resume and we had to start over.
To track _actual_ transfer if the output file could already exist,
the listener should keep its own counter,
or subtract the initial alreadyTransferred value.
And watch out for alreadyTransferred resetting if a resume failed...currentWrite - since last call to the listenerbytesTransferred - includes headers, retries, redirects, discarded partial downloads, ...bytesRemaining - on this attempt only, currentWrite already subtracted -
or -1 if chunked encoding or server does not return a lengthpublic String getBaseName()
getBaseName in class Snarkpublic long getDownloaded()
SnarkgetDownloaded in class Snarkpublic long getDownloadRate()
SnarkgetDownloadRate in class Snarkpublic byte[] getInfoHash()
getInfoHash in class Snarkpublic String getName()
public long getNeededLength()
SnarkgetNeededLength in class Snarkpublic int getPeerCount()
getPeerCount in class Snarkpublic long getRemainingLength()
SnarkgetRemainingLength in class Snarkpublic long getTotalLength()
getTotalLength in class Snarkpublic int getTrackerSeenPeers()
getTrackerSeenPeers in class Snarkpublic void headerReceived(String url, int attemptNum, String key, String val)
EepGet.StatusListenerheaderReceived in interface EepGet.StatusListenerpublic 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.StatusListeneroutputFile - null if unknown (output stream constructor)EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt)
transferFailed in interface EepGet.StatusListenerEepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)