Methods Summary |
---|
public void | close()Closes connection as well as the input stream and
the output stream openning for this connection.
IOException ioe = null;
try {
is.close();
} catch (IOException e) {
ioe = e;
}
try {
os.close();
} catch (IOException e) {
ioe = e;
}
try {
sock.close();
} catch (IOException e) {
ioe = e;
}
// catch IOException if any of the above call has thrown one
if (ioe != null) {
throw ioe;
}
|
private final int | decodeLength16(byte[] buffer, int off)
return ((((int)buffer[off]) & 0xFF) << 8)
+ (((int)buffer[off + 1]) & 0xFF);
|
public int | getMaximumPacketSize()Determines the amount of data (maximum packet size) that can
be successfully sent in a single write operation. If the size
of data is greater than the maximum packet size, then then only
the first maximum packet size bytes of the packet are sent,
and the rest will be discarded.
return Configuration.getIntProperty(
"obex.packetLength.max", 4096);
|
public javax.microedition.io.Connection | getUnderlyingConnection()Get underlying connection.
return sock;
|
public int | read(byte[] inData)Reads the packet data into specified buffer.
If the specified buffer length is 0, then 0 data
will be read into this buffer, and the rest of packet
data is lost.
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 up to len bytes of data from the input stream into
an array of bytes.
while (size != 0) {
int count = is.read(array, offset, size);
if (count == -1) {
throw new IOException("read error");
}
offset += count;
size -= count;
}
|
public void | write(byte[] outData, int len)
os.write(outData, 0, len);
os.flush();
|