FileDocCategorySizeDatePackage
IrOBEXConnection.javaAPI DocphoneME MR2 API (J2ME)4753Wed May 02 18:00:30 BST 2007com.sun.midp.io.j2me.irdaobex

IrOBEXConnection

public class IrOBEXConnection extends Object implements com.sun.kvem.jsr082.obex.ObexTransport
Provides the implemetation of the OBEX over IrDA transport.

Fields Summary
boolean
isClosed
Indicates whether this connection has been closed
private javax.microedition.io.StreamConnection
conn
Underlying connection.
private InputStream
input
Input stream provided by the underlying connection.
private OutputStream
output
Output stream provided by the underlying connection.
Constructors Summary
public IrOBEXConnection(javax.microedition.io.StreamConnection conn)
Creates this connection using the underlying stream connection.

param
conn undelying connection object
throws
IOException if the connection can not be established


                               
         
	this.conn = conn;
	input = conn.openInputStream();
	output = conn.openOutputStream();
    
Methods Summary
public voidclose()
Closes this connection and the underlying connection.

throws
IOException if an I/O error occurs

        synchronized (this) {
            if (isClosed) {
                return;
            }
            isClosed = true;
        }
	input.close();
	output.close();
	conn.close();
    
public final intgetMaximumPacketSize()
Returns the amount of data that can be successfully sent or received in a single read/write operation.

return
the maximum packet size, or zero if any size may be used

        return Configuration.getIntProperty("obex.packetLength.max", 0);
    
public javax.microedition.io.ConnectiongetUnderlyingConnection()
Returns the underlying connection, or null if there is none.

return
underlying connection object

        return conn;
    
public intread(byte[] inData)
Reads the packet data into the specified buffer.

param
inData destination buffer
throws
IOException if an I/O error occurs
throws
NullPointerException if the specified buffer is null
return
number of bytes read

	if (isClosed) {
	    throw new IOException("The connection is closed.");
	}
	if (inData == null) {
	    throw new NullPointerException("Input buffer is null.");
	}
	int size = getMaximumPacketSize();
	int len = inData.length;
	if (size == 0 || len <= size) {
	    return input.read(inData, 0, len);
	}
	int off = 0;
	while (off < len) {
	    int count =	input.read(inData, off, Math.min(size, len - off));
	    if (count == 0) {
		break;
	    }
	    off += count;
	}
	return off;
    
public voidwrite(byte[] outData, int len)
Transfer the len bytes from specified packet over the irda connection.

param
outData source buffer
param
len data length
throws
IOException if an I/O error occurs
throws
NullPointerException if the specified buffer is null

	if (isClosed) {
	    throw new IOException("The connection is closed.");
	}
	if (outData == null) {
	    throw new NullPointerException("Output buffer is null.");
	}
	int size = getMaximumPacketSize();
	if (size == 0 || len <= size) {
	    output.write(outData, 0, len);
	    return;
	}
	int off = 0;
	while (off < len) {
	    int count = Math.min(size, len - off);
	    output.write(outData, off, count);
	    off += count;
	}