Skip to content

Commit 848a1e3

Browse files
Jaikumar GaneshAndroid Code Review
authored andcommitted
Merge "OBEX: Fix PrivateOutputStream small write problem"
2 parents 6c42761 + a9c4c59 commit 848a1e3

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)