Hi
Is there a way to calculate or measure the transfer rate of a file?
in the bytesTransferred(long bytes) method, I have
bytes transered for file
bytes transfered since bytesTransferred(long bytes) was last called
start is a global variable, initially set to 0;
The problem I am having is that sometimes this is fired and the time taken is only a few ms, sometimes 5 or even 1 which causes my transfer rate to be upto 8MB when my broadband connection is 200Kb/s.
Also, how efficient is the ftp library? Does it get good transfer rates compared to command line ftp?
Thanks,
Rob
public void bytesTransferred(long bytes) {
long end = System.currentTimeMillis();
Log.debug("End : " + end);
long begin = start;
Log.debug("Begin : " + begin);
start = System.currentTimeMillis();
long bytesChunk = bytes - bytesSinceLastUpdate;
float kps = 1;
if (begin > 0) {
float timeTaken = end - begin;
Log.debug("Time taken : " + timeTaken);
timeTaken = timeTaken / 1000;
float k = bytesChunk/1024;
kps = k/timeTaken;
Log.debug(kps+"KB/s");
Log.debug("Chunk bytes : " + bytesChunk);
}
totalBytesTransfered += bytesChunk;
Log.debug(bytes + "bytes transferred");
Log.debug(fileSize + "bytes to transfer");
Log.debug(bytes/fileSize*100 + "%");
Log.debug("Total transfered : " + totalBytesTransfered);
Log.debug("Total to transfer : " + totalBytesToTransfer);
Log.debug("Total : " + (totalBytesTransfered/totalBytesToTransfer)*100 + "%");
Log.debug("Total time left " + (totalBytesToTransfer/1000) / kps + " seconds");
bytesSinceLastUpdate = bytes;
}