summaryrefslogtreecommitdiffstats
path: root/obex/javax/obex/ClientOperation.java
diff options
context:
space:
mode:
Diffstat (limited to 'obex/javax/obex/ClientOperation.java')
-rw-r--r--obex/javax/obex/ClientOperation.java46
1 files changed, 24 insertions, 22 deletions
diff --git a/obex/javax/obex/ClientOperation.java b/obex/javax/obex/ClientOperation.java
index 9e0700f..05b498c 100644
--- a/obex/javax/obex/ClientOperation.java
+++ b/obex/javax/obex/ClientOperation.java
@@ -37,6 +37,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
+import java.io.ByteArrayOutputStream;
/**
* This class implements the <code>Operation</code> interface. It will read and
@@ -71,8 +72,6 @@ public final class ClientOperation implements Operation, BaseStream {
private boolean mEndOfBodySent;
- private ObexByteBuffer mOutBuffer;
-
/**
* Creates new OperationImpl to read and write data to a server
* @param maxSize the maximum packet size
@@ -101,8 +100,6 @@ public final class ClientOperation implements Operation, BaseStream {
mRequestHeader = new HeaderSet();
- mOutBuffer = new ObexByteBuffer(32);
-
int[] headerList = header.getHeaderList();
if (headerList != null) {
@@ -399,7 +396,7 @@ public final class ClientOperation implements Operation, BaseStream {
*/
private boolean sendRequest(int opCode) throws IOException {
boolean returnValue = false;
-
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
int bodyLength = -1;
byte[] headerArray = ObexHelper.createHeader(mRequestHeader, true);
if (mPrivateOutput != null) {
@@ -440,9 +437,9 @@ public final class ClientOperation implements Operation, BaseStream {
throw new IOException("OBEX Packet exceeds max packet size");
}
- mOutBuffer.reset();
- mOutBuffer.write(headerArray, start, end - start);
- if (!mParent.sendRequest(opCode, mOutBuffer, mReplyHeader, mPrivateInput)) {
+ byte[] sendHeader = new byte[end - start];
+ System.arraycopy(headerArray, start, sendHeader, 0, sendHeader.length);
+ if (!mParent.sendRequest(opCode, sendHeader, mReplyHeader, mPrivateInput)) {
return false;
}
@@ -459,8 +456,7 @@ public final class ClientOperation implements Operation, BaseStream {
return false;
}
} else {
- mOutBuffer.reset();
- mOutBuffer.write(headerArray);
+ out.write(headerArray);
}
if (bodyLength > 0) {
@@ -475,6 +471,8 @@ public final class ClientOperation implements Operation, BaseStream {
bodyLength = mMaxPacketSize - headerArray.length - 6;
}
+ byte[] body = mPrivateOutput.readBytes(bodyLength);
+
/*
* Since this is a put request if the final bit is set or
* the output stream is closed we need to send the 0x49
@@ -482,40 +480,44 @@ public final class ClientOperation implements Operation, BaseStream {
*/
if ((mPrivateOutput.isClosed()) && (!returnValue) && (!mEndOfBodySent)
&& ((opCode & 0x80) != 0)) {
- mOutBuffer.write((byte)0x49);
+ out.write(0x49);
mEndOfBodySent = true;
} else {
- mOutBuffer.write((byte)0x48);
+ out.write(0x48);
}
bodyLength += 3;
- mOutBuffer.write((byte)(bodyLength >> 8));
- mOutBuffer.write((byte)bodyLength);
- mPrivateOutput.writeTo(mOutBuffer, bodyLength - 3);
+ out.write((byte)(bodyLength >> 8));
+ out.write((byte)bodyLength);
+
+ if (body != null) {
+ out.write(body);
+ }
}
if (mPrivateOutputOpen && bodyLength <= 0 && !mEndOfBodySent) {
// only 0x82 or 0x83 can send 0x49
if ((opCode & 0x80) == 0) {
- mOutBuffer.write((byte)0x48);
+ out.write(0x48);
} else {
- mOutBuffer.write((byte)0x49);
+ out.write(0x49);
mEndOfBodySent = true;
+
}
bodyLength = 3;
- mOutBuffer.write((byte)(bodyLength >> 8));
- mOutBuffer.write((byte)bodyLength);
+ out.write((byte)(bodyLength >> 8));
+ out.write((byte)bodyLength);
}
- if (mOutBuffer.getLength() == 0) {
+ if (out.size() == 0) {
if (!mParent.sendRequest(opCode, null, mReplyHeader, mPrivateInput)) {
return false;
}
return returnValue;
}
- if ((mOutBuffer.getLength() > 0)
- && (!mParent.sendRequest(opCode, mOutBuffer, mReplyHeader, mPrivateInput))) {
+ if ((out.size() > 0)
+ && (!mParent.sendRequest(opCode, out.toByteArray(), mReplyHeader, mPrivateInput))) {
return false;
}