Permalink
Browse files

Merge "OBEX: Fix PrivateOutputStream small write problem"

  • Loading branch information...
2 parents 6c42761 + a9c4c59 commit 848a1e3d8522129c8a39d198a10b134926d71bd2 Jaikumar Ganesh committed with Android Code Review May 20, 2011
Showing with 9 additions and 12 deletions.
  1. +9 −12 obex/javax/obex/PrivateOutputStream.java
@@ -107,18 +107,15 @@ public synchronized void write(byte[] buffer, int offset, int count) throws IOEx
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);
}
}

0 comments on commit 848a1e3

Please sign in to comment.