summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Ljungberg <erik.ljungberg@sonyericsson.com>2011-05-20 12:39:18 +0200
committerJohan Redestig <johan.redestig@sonyericsson.com>2011-05-20 12:39:18 +0200
commita9c4c594ef29e097be8be0537657fa8d9529502e (patch)
treeb244ee37da3c234b009401df790336f658a65e4c
parent6c427617be940be32fdebbd9c78f9223b292c814 (diff)
downloadframeworks_base-a9c4c594ef29e097be8be0537657fa8d9529502e.zip
frameworks_base-a9c4c594ef29e097be8be0537657fa8d9529502e.tar.gz
frameworks_base-a9c4c594ef29e097be8be0537657fa8d9529502e.tar.bz2
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
-rw-r--r--obex/javax/obex/PrivateOutputStream.java21
1 files changed, 9 insertions, 12 deletions
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);
}
}