OSDN Git Service

OBEX: Fix PrivateOutputStream small write problem
authorErik Ljungberg <erik.ljungberg@sonyericsson.com>
Fri, 20 May 2011 10:39:18 +0000 (12:39 +0200)
committerJohan Redestig <johan.redestig@sonyericsson.com>
Fri, 20 May 2011 10:39:18 +0000 (12:39 +0200)
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

index ca420af..713f4ae 100644 (file)
@@ -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);
         }
     }