TCPOBEXConnectionpublic class TCPOBEXConnection extends Object implements com.sun.kvem.jsr082.obex.ObexTransportProvides TCP OBEX underlying stream connection as a transport to
shared OBEX implementation. |
Fields Summary |
---|
private boolean | isClosedIndicates if this notifier has been closed. | private InputStream | inKeeps the correspondent input stream. | private OutputStream | outKeeps the correspondent output stream. |
Constructors Summary |
---|
protected TCPOBEXConnection(com.sun.midp.security.SecurityToken securityToken, String host, int port)Opens the underlaying tcp/socket connection and
initiates the streams.
Protocol sp = new Protocol();
StreamConnection conn = (StreamConnection) sp.openPrim(securityToken,
"//" + host + ":" + port);
// do not delay request since this delays the response.
sp.setSocketOption(SocketConnection.DELAY, 0);
in = conn.openInputStream();;
out = conn.openOutputStream();
conn.close();
| protected TCPOBEXConnection(Object[] streams)Used by notifier that opened tcp/socket connection -
just copy the streams here.
in = (InputStream) streams[0];
out = (OutputStream) streams[1];
|
Methods Summary |
---|
public void | close()Closes this connection.
synchronized (TCPOBEXConnection.class) {
if (isClosed) {
return;
}
isClosed = true;
}
boolean hasException = false;
try {
in.close();
} catch (IOException e) {
hasException = true;
}
try {
out.close();
} catch (IOException e) {
hasException = true;
}
if (hasException) {
throw new IOException("Can't close connection");
}
| private final int | decodeLength16(byte[] buffer, int off)Interprets two bytes located in buffer with off
offset as packet length.
return ((((int)buffer[off]) & 0xFF) << 8)
+ (((int)buffer[off + 1]) & 0xFF);
| public int | getMaximumPacketSize()Gets maximum packet size.
return Configuration.getIntProperty(
"obex.packetLength.max", 4096);
| public javax.microedition.io.Connection | getUnderlyingConnection()Gets underlying connection.
return null;
| public int | read(byte[] inData)Reading obex packet.
readFully(inData, 0, 3); // read header
int packetLength = decodeLength16(inData, 1);
if (packetLength < 3 || packetLength > inData.length) {
throw new IOException("protocol error");
}
readFully(inData, 3, packetLength - 3);
return packetLength;
| private final void | readFully(byte[] array, int offset, int size)Reads size bytes of data from the connection
into an array of bytes.
while (size != 0) {
int count = in.read(array, offset, size);
if (count == -1) {
throw new IOException("read error");
}
offset += count;
size -= count;
}
| public void | write(byte[] outData, int len)Writing obex packet.
out.write(outData, 0, len);
out.flush();
|
|