1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 16:22:06 +01:00

Improve FileTransfer.writeToStream()

let's use the standard idiom for Input- to OutputStream transfers. This
also avoids an initial no-op on the first write, when the count is '0'.

Also fixes a bug when the size of file/stream transferred is '0' (which
is perfectly fine and possible).
This commit is contained in:
Florian Schmaus 2014-09-09 12:49:01 +02:00
parent 090f7cfc49
commit d8db43e4c5

View file

@ -206,15 +206,10 @@ public abstract class FileTransfer {
int count = 0; int count = 0;
amountWritten = 0; amountWritten = 0;
do { while ((count = in.read(b)) > 0 && !getStatus().equals(Status.cancelled)) {
// write to the output stream
out.write(b, 0, count); out.write(b, 0, count);
amountWritten += count; amountWritten += count;
}
// read more bytes from the input stream
count = in.read(b);
} while (count != -1 && !getStatus().equals(Status.cancelled));
// the connection was likely terminated abruptly if these are not equal // the connection was likely terminated abruptly if these are not equal
if (!getStatus().equals(Status.cancelled) && getError() == Error.none if (!getStatus().equals(Status.cancelled) && getError() == Error.none