diff options
author | Steve Kondik <shade@chemlab.org> | 2010-12-02 09:28:09 -0500 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2010-12-02 10:09:45 -0500 |
commit | 04d8fc705dcd80dd0a91f9f811c6aa8fe7329ba6 (patch) | |
tree | 05b9bc425be6e9964b73518d49eaff792bf8552a /obex/javax/obex/PrivateOutputStream.java | |
parent | 32a8f309fc2fc0e6da5b110817d977d4271e853b (diff) | |
download | frameworks_base-04d8fc705dcd80dd0a91f9f811c6aa8fe7329ba6.zip frameworks_base-04d8fc705dcd80dd0a91f9f811c6aa8fe7329ba6.tar.gz frameworks_base-04d8fc705dcd80dd0a91f9f811c6aa8fe7329ba6.tar.bz2 |
Revert "Increase javax.obex performance"
This reverts commit 4cecacb08a3d781a68f8b2be6df620277bb35e17.
There are some problems with this patch. UUIDs in the HeaderSet are
being padded with 16 extra null bytes, which breaks PBAP and FTP
profiles.
Reverting until I have a chance to debug it.
Change-Id: I1e79a8b026b230c5a7dc4c9576489267e7695643
Diffstat (limited to 'obex/javax/obex/PrivateOutputStream.java')
-rw-r--r-- | obex/javax/obex/PrivateOutputStream.java | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/obex/javax/obex/PrivateOutputStream.java b/obex/javax/obex/PrivateOutputStream.java index 06dd55e..ca420af 100644 --- a/obex/javax/obex/PrivateOutputStream.java +++ b/obex/javax/obex/PrivateOutputStream.java @@ -34,6 +34,7 @@ package javax.obex; import java.io.IOException; import java.io.OutputStream; +import java.io.ByteArrayOutputStream; /** * This object provides an output stream to the Operation objects used in this @@ -44,7 +45,7 @@ public final class PrivateOutputStream extends OutputStream { private BaseStream mParent; - private ObexByteBuffer mBuffer; + private ByteArrayOutputStream mArray; private boolean mOpen; @@ -56,7 +57,7 @@ public final class PrivateOutputStream extends OutputStream { */ public PrivateOutputStream(BaseStream p, int maxSize) { mParent = p; - mBuffer = new ObexByteBuffer(32); + mArray = new ByteArrayOutputStream(); mMaxPacketSize = maxSize; mOpen = true; } @@ -66,7 +67,7 @@ public final class PrivateOutputStream extends OutputStream { * @return the number of bytes written to the output stream */ public int size() { - return mBuffer.getLength(); + return mArray.size(); } /** @@ -81,8 +82,8 @@ public final class PrivateOutputStream extends OutputStream { public synchronized void write(int b) throws IOException { ensureOpen(); mParent.ensureNotDone(); - mBuffer.write((byte)b); - if (mBuffer.getLength() == mMaxPacketSize) { + mArray.write(b); + if (mArray.size() == mMaxPacketSize) { mParent.continueOperation(true, false); } } @@ -107,30 +108,38 @@ public final class PrivateOutputStream extends OutputStream { ensureOpen(); mParent.ensureNotDone(); if (count < mMaxPacketSize) { - mBuffer.write(buffer, offset, count); + mArray.write(buffer, offset, count); } else { while (remainLength >= mMaxPacketSize) { - mBuffer.write(buffer, offset1, mMaxPacketSize); + mArray.write(buffer, offset1, mMaxPacketSize); offset1 += mMaxPacketSize; remainLength = count - offset1; mParent.continueOperation(true, false); } if (remainLength > 0) { - mBuffer.write(buffer, offset1, remainLength); + mArray.write(buffer, offset1, remainLength); } } } /** - * Write some of the bytes that have been written to this stream to - * an ObexByteBuffer. - * - * @param dest the stream to write to - * @param start where to write in the byte array - * @param size the number of bytes to write to the byte array + * Reads the bytes that have been written to this stream. + * @param size the size of the array to return + * @return the byte array that is written */ - public synchronized void writeTo(ObexByteBuffer dest, int size) throws IOException { - mBuffer.read(dest, size); + public synchronized byte[] readBytes(int size) { + if (mArray.size() > 0) { + byte[] temp = mArray.toByteArray(); + mArray.reset(); + byte[] result = new byte[size]; + System.arraycopy(temp, 0, result, 0, size); + if (temp.length != size) { + mArray.write(temp, size, temp.length - size); + } + return result; + } else { + return null; + } } /** |