mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 05:52: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:
parent
090f7cfc49
commit
d8db43e4c5
1 changed files with 4 additions and 9 deletions
|
@ -206,15 +206,10 @@ public abstract class FileTransfer {
|
|||
int count = 0;
|
||||
amountWritten = 0;
|
||||
|
||||
do {
|
||||
// write to the output stream
|
||||
out.write(b, 0, count);
|
||||
|
||||
amountWritten += count;
|
||||
|
||||
// read more bytes from the input stream
|
||||
count = in.read(b);
|
||||
} while (count != -1 && !getStatus().equals(Status.cancelled));
|
||||
while ((count = in.read(b)) > 0 && !getStatus().equals(Status.cancelled)) {
|
||||
out.write(b, 0, count);
|
||||
amountWritten += count;
|
||||
}
|
||||
|
||||
// the connection was likely terminated abruptly if these are not equal
|
||||
if (!getStatus().equals(Status.cancelled) && getError() == Error.none
|
||||
|
|
Loading…
Reference in a new issue