Small patch for FileTransfer

Here is a small patch for org.jivesoftware.smackx.filetransfer.FileTransfer

The current getProgress method only returns 2 values : 0 (during the transfer) and 1 when the transfer finishes.

fileSize should be cast to double in order to return the real progress.

I also added some checks because amountWritten is init with -1 and fileSize creates an exception (divide by zero) if getProgress is called too early.

Old :

public double getProgress() {

if(amountWritten == 0) {

return 0;

}

return amountWritten / fileSize;

}

New:

public double getProgress() {

if(amountWritten <= 0 || fileSize <= 0) {

return 0;

}

return amountWritten / (double)fileSize;

}

Nicolas

Hi Nico,

a nice code snipped, checking for (amountWritten == 0) is really useless as amountWritten is divided and 0 / fileSize is always 0 (as long as fileSize != 0). I like your code as it checks also the divisor.

LG

hey nricheton,

Yea, I had noticed that before and thought I had already checked in a fix for it. Guess I didn’'t, thanks for the heads up I will implement that fix!

Alex

Hey Guys,

The fix - SMACK-127 - is in the next nightly build.

Thanks,

Alex