Java Reference
In-Depth Information
The fact that OBEX is a request/response protocol modeled after HTTP is quite evident
from Table 12-7.
Communications Using PUT or GET
User-defined headers are sufficient for communication tasks that are based on exchange of
small messages. For communications that involve custom data types or large binary objects
(files, images, etc.), you can use the PUT and GET requests. The put() method on ClientSession
can be used to initiate a PUT request.
Operation put(HeaderSet headers) ;
Note that you can still include a HeaderSet for the request. For example, you may want to
let the server application know the length and data type of the object that you will be sending—
and you can set the appropriate headers.
To obtain a large data object from a server, use the get() method on ClientSession :
Operation get(HeaderSet headers);
Again, you can set the header of the request. Note that the headers from the response of
the server are not directly accessible. Instead, you can use the following methods to obtain
some pertinent header information (if they are set by the server):
getLength() to obtain the value from the standard OBEX header: LENGTH
getType() to obtain the value from the standard OBEX header: TYPE
Once you have an Operation instance from the get() method call, you can call one of
the following:
openInputStream() to obtain an InputStream
openDataInputStream() to obtain a DataInputStream
Once you have an Operation instance from a put() method call, you can call one of these
methods:
openOutputStream() to obtain an OutputStream
openDataOutputStream() to obtain a DataOutputStream
With the stream opened, you can use the read or write methods of the stream to process
the incoming or outgoing data object. The OBEX implementation underneath will perform the
necessary segmenting of packets, sending them, and reassembing them for you. This is one of
the primary benefits of using the OBEX high-level API instead of lower-level packet-based APIs.
You can close the stream once you are finished reading/writing. Note that once you close
the stream, the OBEX implementation underneath will be sending packets to the server that
indicate the operation is completed. The server will send a response code; this response code
can be obtained using the following:
int getResponseCode();
Search WWH ::




Custom Search