download package - librespeed/speedtest-android GitHub Wiki
Downloader
class
A Thread that uses a Connection to download an endless stream of garbage data from the server. The download starts immediately (no need to call start()
).
Constructor:
public Downloader(Connection c, String path, int ckSize)
c
: the instance of Connection to be usedpath
: path on the server where the garbage data can be fetchedckSize
: size in megabytes of the garbage data (also see documentation for garbage.php)
Important: If you're not using garbage.php
, your replacement must accept the ckSize
parameter; if you're using a large file of garbage data, it needs to be at least ckSize
megabytes for this downloader to work properly.
This thread repeatedly sends a GET request to the speified path
and download all the data coming to it. When the amount of downloaded data is nearing ckSize (75%), a new request is made to ensure a steady flow of data.
Callbacks:
onProgress(long downloaded)
: periodically called to inform of how much data was downloaded. (Max once every 200ms)onError(String err)
: called if something goes wrong.err
contains the error message
Methods:
stopASAP()
: asks to stop the download as soon as possible. The Connection will also be closed. Usejoin()
to wait for the thread to dieresetDownloadCounter()
: resets the counter of the amount of downloaded datagetDownloaded()
: returns the amount of downloaded data since the beginning or last reset
DownloadStream
class
A stream for the download test. Manages a Connection and a Downloader, and handles errors according to the specified policy. Starts immediately.
Constructor:
public DownloadStream(String server, String path, int ckSize, String errorHandlingMode, int connectTimeout, int soTimeout, int recvBuffer, int sendBuffer, Logger log)
server
: URL to the server where we need to connectpath
: path on the server where the garbage data can be fetchedckSize
: size in megabytes of the garbage dataerrorHandlingMode
: what we should do in case of errors:- SpeedtestConfig.ONERROR_FAIL: Fail immediately
- SpeedtestConfig.ONERROR_ATTEMPT_RESTART: Try to reconnect. If that fails, the stream fails
- SpeedtestConfig.ONERROR_MUST_RESTART: Keep trying to reconnect until we succeed (or stopped)
connectTimeout
,soTimeout
,recvBuffer
,sendBuffer
: settings for the socket created by Connectionlog
: instance of Logger that is used to report errors such as dead connections
Callbacks:
onError(String err)
: called if the stream fails.err
contains the error message
Methods:
stopASAP()
: asks to stop the download as soon as possible. The Connection will also be closed. Usejoin()
to wait for the connection to be actually closedresetDownloadCounter()
: resets the counter of the amount of downloaded datagetTotalDownloaded()
: returns the amount of downloaded data since the beginning or last resetjoin()
: waits for the instance of Downloader to die