From d8db43e4c59dc038c444c575b90e9405b1528a8d Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 9 Sep 2014 12:49:01 +0200 Subject: [PATCH] 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). --- .../smackx/filetransfer/FileTransfer.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java index baed208d0..586c934cd 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java @@ -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