Methods Summary |
---|
public javax.obex.HeaderSet | connect(javax.obex.HeaderSet headers)
lockCheckHeaders(headers);
try {
if (isConnected) {
throw new IOException("already connected");
}
byte[] head = {
(byte)OPCODE_CONNECT,
0, 0, // length will be here
0x10, // obex protocol version 1.0
0x00, // flags, all zero for this version of OBEX
// maximum client supported packet length
(byte) (OBEX_MAXIMUM_PACKET_LENGTH / 0x100),
(byte) (OBEX_MAXIMUM_PACKET_LENGTH % 0x100),
};
sendPacket(head, -1, (HeaderSetImpl) headers, true);
recvPacket();
if (packetLength < 7 || buffer[3] != 0x10) {
// IMPL_NOTE: It is not decided what the implementation should do
// if the OBEX version does not match. For example, Windows
// implementation uses version 1.2, Linux implementation
// uses version 1.1. JSR-82 should probably work with both.
// throw new IOException("unsupported server obex version");
}
HeaderSetImpl recvHeaders = new HeaderSetImpl(owner);
parsePacketHeaders(recvHeaders, 7);
if (shouldSendAuthResponse()) {
// server ignores challenge before authenticating client
authFailed = false;
sendPacket(head, -1, (HeaderSetImpl) headers, true);
recvPacket();
if (packetLength < 7 || buffer[3] != 0x10) {
// IMPL_NOTE: See the comment above.
// throw new IOException("unsupported server obex version");
}
recvHeaders = new HeaderSetImpl(owner);
parsePacketHeaders(recvHeaders, 7);
}
maxSendLength = decodeLength16(5);
if (maxSendLength > OBEX_MAXIMUM_PACKET_LENGTH) {
maxSendLength = OBEX_MAXIMUM_PACKET_LENGTH;
}
if (packetType == ResponseCodes.OBEX_HTTP_OK) {
if (authFailed) {
throw new IOException("server is not authenticated");
}
isConnected = true;
}
return recvHeaders;
} finally {
unlock();
}
|
public javax.obex.HeaderSet | createHeaderSet()
return new HeaderSetImpl(HeaderSetImpl.OWNER_CLIENT_USER);
|
public javax.obex.HeaderSet | delete(javax.obex.HeaderSet headers)
lockCheckHeaders(headers);
try {
if (!isConnected) {
throw new IOException("not connected");
}
Operation op = new ClientOperation(this,
(HeaderSetImpl)headers, false);
op.getResponseCode(); // indicates end of operation
HeaderSet recvHeaders = op.getReceivedHeaders();
op.close();
return recvHeaders;
} finally {
unlock();
}
|
public javax.obex.HeaderSet | disconnect(javax.obex.HeaderSet headers)
lockCheckHeaders(headers);
try {
if (!isConnected) {
throw new IOException("not connected");
}
sendPacket(PACKET_DISCONNECT, connId,
(HeaderSetImpl) headers, true);
recvPacket();
HeaderSetImpl recvHeaders = new HeaderSetImpl(owner);
parsePacketHeaders(recvHeaders, 3);
if (packetType == ResponseCodes.OBEX_HTTP_OK) {
isConnected = false;
}
return recvHeaders;
} finally {
unlock();
}
|
public javax.obex.Operation | get(javax.obex.HeaderSet headers)
lockCheckHeaders(headers);
try {
if (!isConnected) {
throw new IOException("not connected");
}
new ClientOperation(this, (HeaderSetImpl)headers, true);
return operation;
} finally {
unlock();
}
|
public long | getConnectionID()
return connId;
|
void | headerTooLarge()
throw new IOException("header too large");
|
private void | lockCheckHeaders(javax.obex.HeaderSet headers)
if (isClosed()) {
throw new IOException("session closed");
}
if (operation != null) {
throw new IOException("already in operation");
}
if (headers != null) {
if (!(headers instanceof HeaderSetImpl)
|| ((HeaderSetImpl)headers).owner == owner) {
throw new IllegalArgumentException("wrong headerset class");
}
}
synchronized (lockObject) {
if (busy) {
throw new IOException("already in operation");
}
busy = true;
}
|
void | onAuthenticationFailure(byte[] username)
if (operation != null) {
operation.abort();
}
throw new IOException("server is not authenticated");
|
void | onMissingAuthResponse()
if (packetType != ResponseCodes.OBEX_HTTP_UNAUTHORIZED) {
if (operation != null) {
operation.abort();
}
throw new IOException("no auth response from server");
}
|
public javax.obex.Operation | put(javax.obex.HeaderSet headers)
lockCheckHeaders(headers);
try {
if (!isConnected) {
throw new IOException("not connected");
}
new ClientOperation(this,
(HeaderSetImpl) headers, false);
return operation;
} finally {
unlock();
}
|
public void | setConnectionID(long id)
if (id < 0L || id > 0xFFFFFFFFL) {
throw new IllegalArgumentException("invalid id");
}
connId = id;
|
public javax.obex.HeaderSet | setPath(javax.obex.HeaderSet headers, boolean backup, boolean create)
lockCheckHeaders(headers);
try {
if (!isConnected) {
throw new IOException("not connected");
}
byte[] head = {
(byte)OPCODE_SETPATH,
0, 0, // length will be here
(byte)((backup ? 1 : 0) + (create ? 0 : 2)), // flags
0x00, // constants
};
sendPacket(head, connId, (HeaderSetImpl) headers, true);
recvPacket();
HeaderSetImpl recvHeaders = new HeaderSetImpl(owner);
parsePacketHeaders(recvHeaders, 3);
return recvHeaders;
} finally {
unlock();
}
|
private void | unlock()
synchronized (lockObject) {
busy = false;
}
|