Skip to content

Commit a9c4c59

Browse files
Erik LjungbergJohan Redestig
authored andcommitted
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
1 parent 6c42761 commit a9c4c59

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

obex/javax/obex/PrivateOutputStream.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,15 @@ public synchronized void write(byte[] buffer, int offset, int count) throws IOEx
107107

108108
ensureOpen();
109109
mParent.ensureNotDone();
110-
if (count < mMaxPacketSize) {
111-
mArray.write(buffer, offset, count);
112-
} else {
113-
while (remainLength >= mMaxPacketSize) {
114-
mArray.write(buffer, offset1, mMaxPacketSize);
115-
offset1 += mMaxPacketSize;
116-
remainLength = count - offset1;
117-
mParent.continueOperation(true, false);
118-
}
119-
if (remainLength > 0) {
120-
mArray.write(buffer, offset1, remainLength);
121-
}
110+
while ((mArray.size() + remainLength) >= mMaxPacketSize) {
111+
int bufferLeft = mMaxPacketSize - mArray.size();
112+
mArray.write(buffer, offset1, bufferLeft);
113+
offset1 += bufferLeft;
114+
remainLength -= bufferLeft;
115+
mParent.continueOperation(true, false);
116+
}
117+
if (remainLength > 0) {
118+
mArray.write(buffer, offset1, remainLength);
122119
}
123120
}
124121

0 commit comments

Comments
 (0)