summaryrefslogtreecommitdiffstats
path: root/obex/javax/obex/ServerSession.java
diff options
context:
space:
mode:
Diffstat (limited to 'obex/javax/obex/ServerSession.java')
-rw-r--r--obex/javax/obex/ServerSession.java96
1 files changed, 57 insertions, 39 deletions
diff --git a/obex/javax/obex/ServerSession.java b/obex/javax/obex/ServerSession.java
index 694c8a9..a4b9759 100644
--- a/obex/javax/obex/ServerSession.java
+++ b/obex/javax/obex/ServerSession.java
@@ -60,10 +60,6 @@ public final class ServerSession extends ObexSession implements Runnable {
private boolean mClosed;
- private ObexByteBuffer mData;
-
- private ObexByteBuffer mHeaderBuffer;
-
/**
* Creates new ServerSession.
* @param trans the connection to the client
@@ -84,9 +80,6 @@ public final class ServerSession extends ObexSession implements Runnable {
mClosed = false;
mProcessThread = new Thread(this);
mProcessThread.start();
-
- mData = new ObexByteBuffer(32);
- mHeaderBuffer = new ObexByteBuffer(32);
}
/**
@@ -260,22 +253,24 @@ public final class ServerSession extends ObexSession implements Runnable {
* @param header the headers to include in the response
* @throws IOException if an IO error occurs
*/
- public void sendResponse(int code, ObexByteBuffer header) throws IOException {
+ public void sendResponse(int code, byte[] header) throws IOException {
int totalLength = 3;
- mData.reset();
+ byte[] data = null;
if (header != null) {
- totalLength += header.getLength();
- mData.write((byte)code);
- mData.write((byte)(totalLength >> 8));
- mData.write((byte)totalLength);
- mData.write(header);
+ totalLength += header.length;
+ data = new byte[totalLength];
+ data[0] = (byte)code;
+ data[1] = (byte)(totalLength >> 8);
+ data[2] = (byte)totalLength;
+ System.arraycopy(header, 0, data, 3, header.length);
} else {
- mData.write((byte)code);
- mData.write((byte)0x00);
- mData.write((byte)totalLength);
+ data = new byte[totalLength];
+ data[0] = (byte)code;
+ data[1] = (byte)0x00;
+ data[2] = (byte)totalLength;
}
- mData.read(mOutput);
+ mOutput.write(data);
mOutput.flush();
}
@@ -296,6 +291,7 @@ public final class ServerSession extends ObexSession implements Runnable {
int totalLength = 3;
byte[] head = null;
int code = -1;
+ int bytesReceived;
HeaderSet request = new HeaderSet();
HeaderSet reply = new HeaderSet();
@@ -309,10 +305,15 @@ public final class ServerSession extends ObexSession implements Runnable {
totalLength = 3;
} else {
if (length > 5) {
- mData.reset();
- mData.write(mInput, length - 5);
+ byte[] headers = new byte[length - 5];
+ bytesReceived = mInput.read(headers);
- ObexHelper.updateHeaderSet(request, mData, null, mHeaderBuffer);
+ while (bytesReceived != headers.length) {
+ bytesReceived += mInput.read(headers, bytesReceived, headers.length
+ - bytesReceived);
+ }
+
+ ObexHelper.updateHeaderSet(request, headers);
if (mListener.getConnectionId() != -1 && request.mConnectionID != null) {
mListener.setConnectionId(ObexHelper.convertToLong(request.mConnectionID));
@@ -385,18 +386,18 @@ public final class ServerSession extends ObexSession implements Runnable {
}
// Compute Length of OBEX SETPATH packet
- mData.reset();
- mData.write((byte)code);
- mData.write((byte)(totalLength >> 8));
- mData.write((byte)totalLength);
+ byte[] replyData = new byte[totalLength];
+ replyData[0] = (byte)code;
+ replyData[1] = (byte)(totalLength >> 8);
+ replyData[2] = (byte)totalLength;
if (head != null) {
- mData.write(head);
+ System.arraycopy(head, 0, replyData, 3, head.length);
}
/*
* Write the OBEX SETPATH packet to the server. Byte 0: response code
* Byte 1&2: Connect Packet Length Byte 3 to n: headers
*/
- mData.read(mOutput);
+ mOutput.write(replyData);
mOutput.flush();
}
@@ -413,6 +414,7 @@ public final class ServerSession extends ObexSession implements Runnable {
int code = ResponseCodes.OBEX_HTTP_OK;
int totalLength = 3;
byte[] head = null;
+ int bytesReceived;
HeaderSet request = new HeaderSet();
HeaderSet reply = new HeaderSet();
@@ -424,10 +426,15 @@ public final class ServerSession extends ObexSession implements Runnable {
totalLength = 3;
} else {
if (length > 3) {
- mData.reset();
- mData.write(mInput, length - 3);
+ byte[] headers = new byte[length - 3];
+ bytesReceived = mInput.read(headers);
+
+ while (bytesReceived != headers.length) {
+ bytesReceived += mInput.read(headers, bytesReceived, headers.length
+ - bytesReceived);
+ }
- ObexHelper.updateHeaderSet(request, mData, null, mHeaderBuffer);
+ ObexHelper.updateHeaderSet(request, headers);
}
if (mListener.getConnectionId() != -1 && request.mConnectionID != null) {
@@ -478,18 +485,23 @@ public final class ServerSession extends ObexSession implements Runnable {
}
// Compute Length of OBEX CONNECT packet
- mData.reset();
- mData.write((byte)code);
- mData.write((byte)(totalLength >> 8));
- mData.write((byte)totalLength);
+ byte[] replyData;
+ if (head != null) {
+ replyData = new byte[3 + head.length];
+ } else {
+ replyData = new byte[3];
+ }
+ replyData[0] = (byte)code;
+ replyData[1] = (byte)(totalLength >> 8);
+ replyData[2] = (byte)totalLength;
if (head != null) {
- mData.write(head);
+ System.arraycopy(head, 0, replyData, 3, head.length);
}
/*
* Write the OBEX DISCONNECT packet to the server. Byte 0: response code
* Byte 1&2: Connect Packet Length Byte 3 to n: headers
*/
- mData.read(mOutput);
+ mOutput.write(replyData);
mOutput.flush();
}
@@ -513,6 +525,7 @@ public final class ServerSession extends ObexSession implements Runnable {
int code = -1;
HeaderSet request = new HeaderSet();
HeaderSet reply = new HeaderSet();
+ int bytesReceived;
/*
* Read in the length of the OBEX packet, OBEX version, flags, and max
@@ -535,10 +548,15 @@ public final class ServerSession extends ObexSession implements Runnable {
totalLength = 7;
} else {
if (packetLength > 7) {
- mData.reset();
- mData.write(mInput, packetLength - 7);
+ byte[] headers = new byte[packetLength - 7];
+ bytesReceived = mInput.read(headers);
+
+ while (bytesReceived != headers.length) {
+ bytesReceived += mInput.read(headers, bytesReceived, headers.length
+ - bytesReceived);
+ }
- ObexHelper.updateHeaderSet(request, mData, null, mHeaderBuffer);
+ ObexHelper.updateHeaderSet(request, headers);
}
if (mListener.getConnectionId() != -1 && request.mConnectionID != null) {