From a9c4c594ef29e097be8be0537657fa8d9529502e Mon Sep 17 00:00:00 2001 From: Erik Ljungberg Date: Fri, 20 May 2011 12:39:18 +0200 Subject: OBEX: Fix PrivateOutputStream small write problem When data less than max packet size in length is sent into the write method the data will only be added to the internal buffer. If several calls to write is performed by the application continueOperation will not be called at all. The solution to the problem is to always check the internal buffer size and to call continueOperation every time maxPacketSize bytes is in the internal buffer. Change-Id: I5ebfa3c26db2c1aefe1a115d7782d8ceaa760937 --- obex/javax/obex/PrivateOutputStream.java | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'obex') diff --git a/obex/javax/obex/PrivateOutputStream.java b/obex/javax/obex/PrivateOutputStream.java index ca420af..713f4ae 100644 --- a/obex/javax/obex/PrivateOutputStream.java +++ b/obex/javax/obex/PrivateOutputStream.java @@ -107,18 +107,15 @@ public final class PrivateOutputStream extends OutputStream { ensureOpen(); mParent.ensureNotDone(); - if (count < mMaxPacketSize) { - mArray.write(buffer, offset, count); - } else { - while (remainLength >= mMaxPacketSize) { - mArray.write(buffer, offset1, mMaxPacketSize); - offset1 += mMaxPacketSize; - remainLength = count - offset1; - mParent.continueOperation(true, false); - } - if (remainLength > 0) { - mArray.write(buffer, offset1, remainLength); - } + while ((mArray.size() + remainLength) >= mMaxPacketSize) { + int bufferLeft = mMaxPacketSize - mArray.size(); + mArray.write(buffer, offset1, bufferLeft); + offset1 += bufferLeft; + remainLength -= bufferLeft; + mParent.continueOperation(true, false); + } + if (remainLength > 0) { + mArray.write(buffer, offset1, remainLength); } } -- cgit v1.1