diff options
author | Tao Liejun <L.J.Tao@motorola.com> | 2009-07-13 15:57:11 -0700 |
---|---|---|
committer | Nick Pelly <npelly@google.com> | 2009-07-14 21:20:39 -0700 |
commit | 05ff98bbefda39b9ff26f8bca132cfd0248745c6 (patch) | |
tree | dd7399785790ece3f34d1725972f1a0a128cf4df /obex | |
parent | c047d68372ece9fa74446b13ea66bc12b060b882 (diff) | |
download | frameworks_base-05ff98bbefda39b9ff26f8bca132cfd0248745c6.zip frameworks_base-05ff98bbefda39b9ff26f8bca132cfd0248745c6.tar.gz frameworks_base-05ff98bbefda39b9ff26f8bca132cfd0248745c6.tar.bz2 |
Fix minor obex bugs and re-format the comments
re-format comments
move connectible to connectable
remove unnecessary throws
remove not-used function ClientOperation.readResponse()
fix client abort case for PUT
set mOpen for PrivateOutputStream
add to platform.xml
Diffstat (limited to 'obex')
-rw-r--r-- | obex/javax/obex/Authenticator.java | 89 | ||||
-rw-r--r-- | obex/javax/obex/BaseStream.java | 21 | ||||
-rw-r--r-- | obex/javax/obex/ClientOperation.java | 173 | ||||
-rw-r--r-- | obex/javax/obex/ClientSession.java | 37 | ||||
-rw-r--r-- | obex/javax/obex/HeaderSet.java | 150 | ||||
-rw-r--r-- | obex/javax/obex/ObexHelper.java | 157 | ||||
-rw-r--r-- | obex/javax/obex/ObexSession.java | 12 | ||||
-rw-r--r-- | obex/javax/obex/ObexTransport.java | 1 | ||||
-rw-r--r-- | obex/javax/obex/Operation.java | 101 | ||||
-rw-r--r-- | obex/javax/obex/PasswordAuthentication.java | 16 | ||||
-rw-r--r-- | obex/javax/obex/PrivateInputStream.java | 26 | ||||
-rw-r--r-- | obex/javax/obex/PrivateOutputStream.java | 25 | ||||
-rw-r--r-- | obex/javax/obex/ResponseCodes.java | 9 | ||||
-rw-r--r-- | obex/javax/obex/ServerOperation.java | 125 | ||||
-rw-r--r-- | obex/javax/obex/ServerRequestHandler.java | 192 | ||||
-rw-r--r-- | obex/javax/obex/ServerSession.java | 73 | ||||
-rw-r--r-- | obex/javax/obex/SessionNotifier.java | 127 |
17 files changed, 493 insertions, 841 deletions
diff --git a/obex/javax/obex/Authenticator.java b/obex/javax/obex/Authenticator.java index 7246e91..ec226fb 100644 --- a/obex/javax/obex/Authenticator.java +++ b/obex/javax/obex/Authenticator.java @@ -34,53 +34,50 @@ package javax.obex; /** * This interface provides a way to respond to authentication challenge and - * authentication response headers. When a client or server receives an + * authentication response headers. When a client or server receives an * authentication challenge or authentication response header, the * <code>onAuthenticationChallenge()</code> or - * <code>onAuthenticationResponse()</code> will be called, respectively, by - * the implementation. + * <code>onAuthenticationResponse()</code> will be called, respectively, by the + * implementation. * <P> * For more information on how the authentication procedure works in OBEX, - * please review the IrOBEX specification at - * <A HREF="http://www.irda.org">http://www.irda.org</A>. + * please review the IrOBEX specification at <A + * HREF="http://www.irda.org">http://www.irda.org</A>. * <P> * <STRONG>Authentication Challenges</STRONG> * <P> * When a client or server receives an authentication challenge header, the - * <code>onAuthenticationChallenge()</code> method will be invoked by the - * OBEX API implementation. The application will then return the user name - * (if needed) and password via a <code>PasswordAuthentication</code> object. - * The password in this object is not sent in the authentication response. - * Instead, the 16-byte challenge received in the authentication challenge is - * combined with the password returned from the - * <code>onAuthenticationChallenge()</code> method and passed through the MD5 - * hash algorithm. The resulting value is sent in the authentication response - * along with the user name if it was provided. + * <code>onAuthenticationChallenge()</code> method will be invoked by the OBEX + * API implementation. The application will then return the user name (if + * needed) and password via a <code>PasswordAuthentication</code> object. The + * password in this object is not sent in the authentication response. Instead, + * the 16-byte challenge received in the authentication challenge is combined + * with the password returned from the <code>onAuthenticationChallenge()</code> + * method and passed through the MD5 hash algorithm. The resulting value is sent + * in the authentication response along with the user name if it was provided. * <P> * <STRONG>Authentication Responses</STRONG> * <P> * When a client or server receives an authentication response header, the * <code>onAuthenticationResponse()</code> method is invoked by the API * implementation with the user name received in the authentication response - * header. (The user name will be <code>null</code> if no user name was - * provided in the authentication response header.) The application must - * determine the correct password. This value should be returned from the - * <code>onAuthenticationResponse()</code> method. If the authentication - * request should fail without the implementation checking the password, - * <code>null</code> should - * be returned by the application. (This is needed for reasons like not - * recognizing the user name, etc.) If the returned value is not - * <code>null</code>, the OBEX API implementation will combine the password + * header. (The user name will be <code>null</code> if no user name was provided + * in the authentication response header.) The application must determine the + * correct password. This value should be returned from the + * <code>onAuthenticationResponse()</code> method. If the authentication request + * should fail without the implementation checking the password, + * <code>null</code> should be returned by the application. (This is needed for + * reasons like not recognizing the user name, etc.) If the returned value is + * not <code>null</code>, the OBEX API implementation will combine the password * returned from the <code>onAuthenticationResponse()</code> method and * challenge sent via the authentication challenge, apply the MD5 hash * algorithm, and compare the result to the response hash received in the - * authentication response header. If the values are not equal, an - * <code>IOException</code> will be thrown if the client requested authentication. - * If the server requested authentication, the + * authentication response header. If the values are not equal, an + * <code>IOException</code> will be thrown if the client requested + * authentication. If the server requested authentication, the * <code>onAuthenticationFailure()</code> method will be called on the - * <code>ServerRequestHandler</code> that failed authentication. The - * connection is <B>not</B> closed if authentication failed. - * + * <code>ServerRequestHandler</code> that failed authentication. The connection + * is <B>not</B> closed if authentication failed. * @hide */ public interface Authenticator { @@ -90,35 +87,29 @@ public interface Authenticator { * header. It should respond to the challenge with a * <code>PasswordAuthentication</code> that contains the correct user name * and password for the challenge. - * - * @param description the description of which user name and password - * should be used; if no description is provided in the authentication - * challenge or the description is encoded in an encoding scheme that is - * not supported, an empty string will be provided - * + * @param description the description of which user name and password should + * be used; if no description is provided in the authentication + * challenge or the description is encoded in an encoding scheme that + * is not supported, an empty string will be provided * @param isUserIdRequired <code>true</code> if the user ID is required; - * <code>false</code> if the user ID is not required - * - * @param isFullAccess <code>true</code> if full access to the server - * will be granted; <code>false</code> if read only access will be - * granted - * - * @return a <code>PasswordAuthentication</code> object containing the - * user name and password used for authentication + * <code>false</code> if the user ID is not required + * @param isFullAccess <code>true</code> if full access to the server will + * be granted; <code>false</code> if read only access will be granted + * @return a <code>PasswordAuthentication</code> object containing the user + * name and password used for authentication */ PasswordAuthentication onAuthenticationChallenge(String description, boolean isUserIdRequired, boolean isFullAccess); /** * Called when a client or server receives an authentication response - * header. This method will provide the user name and expect the correct + * header. This method will provide the user name and expect the correct * password to be returned. - * - * @param userName the user name provided in the authentication response; - * may be <code>null</code> - * + * @param userName the user name provided in the authentication response; may + * be <code>null</code> * @return the correct password for the user name provided; if - * <code>null</code> is returned then the authentication request failed + * <code>null</code> is returned then the authentication request + * failed */ byte[] onAuthenticationResponse(byte[] userName); } diff --git a/obex/javax/obex/BaseStream.java b/obex/javax/obex/BaseStream.java index c32717f..022ad4f 100644 --- a/obex/javax/obex/BaseStream.java +++ b/obex/javax/obex/BaseStream.java @@ -37,46 +37,39 @@ import java.io.IOException; /** * This interface defines the methods needed by a parent that uses the * PrivateInputStream and PrivateOutputStream objects defined in this package. - * * @hide */ public interface BaseStream { /** * Verifies that this object is still open. - * * @throws IOException if the object is closed */ void ensureOpen() throws IOException; /** - * Verifies that additional information may be sent. In other words, the + * Verifies that additional information may be sent. In other words, the * operation is not done. - * * @throws IOException if the operation is completed */ void ensureNotDone() throws IOException; /** * Continues the operation since there is no data to read. - * - * @param sendEmpty <code>true</code> if the operation should send an - * empty packet or not send anything if there is no data to send - * @param inStream <code>true</code> if the stream is input stream or - * is output stream + * @param sendEmpty <code>true</code> if the operation should send an empty + * packet or not send anything if there is no data to send + * @param inStream <code>true</code> if the stream is input stream or is + * output stream * @return <code>true</code> if the operation was completed; - * <code>false</code> if no operation took place - * + * <code>false</code> if no operation took place * @throws IOException if an IO error occurs */ boolean continueOperation(boolean sendEmpty, boolean inStream) throws IOException; /** * Called when the output or input stream is closed. - * * @param inStream <code>true</code> if the input stream is closed; - * <code>false</code> if the output stream is closed - * + * <code>false</code> if the output stream is closed * @throws IOException if an IO error occurs */ void streamClosed(boolean inStream) throws IOException; diff --git a/obex/javax/obex/ClientOperation.java b/obex/javax/obex/ClientOperation.java index b3807af..65663b1 100644 --- a/obex/javax/obex/ClientOperation.java +++ b/obex/javax/obex/ClientOperation.java @@ -40,9 +40,8 @@ import java.io.DataOutputStream; import java.io.ByteArrayOutputStream; /** - * This class implements the <code>Operation</code> interface. It will read - * and write data via puts and gets. - * + * This class implements the <code>Operation</code> interface. It will read and + * write data via puts and gets. * @hide */ public final class ClientOperation implements Operation, BaseStream { @@ -73,15 +72,14 @@ public final class ClientOperation implements Operation, BaseStream { private boolean mEndOfBodySent; - /** + /** * Creates new OperationImpl to read and write data to a server * @param maxSize the maximum packet size * @param p the parent to this object * @param type <code>true</code> if this is a get request; - * <code>false</code. if this is a put request - * @param headers the headers to set in the initial request - * - * @throws IOExcpetion if the an IO error occured + * <code>false</code. if this is a put request + * @param header the header to set in the initial request + * @throws IOException if the an IO error occurred */ public ClientOperation(int maxSize, ClientSession p, HeaderSet header, boolean type) throws IOException { @@ -126,20 +124,14 @@ public final class ClientOperation implements Operation, BaseStream { } /** - * Sends an ABORT message to the server. By calling this method, the + * Sends an ABORT message to the server. By calling this method, the * corresponding input and output streams will be closed along with this * object. - * - * @throws IOException if the transaction has already ended or if an - * OBEX server called this method + * @throws IOException if the transaction has already ended or if an OBEX + * server called this method */ public synchronized void abort() throws IOException { ensureOpen(); - // need check again . - // if(isDone) { - // throw new IOException("Operation has already ended"); - // } - //no compatible with sun-ri if ((mOperationDone) && (mReplyHeader.responseCode != ResponseCodes.OBEX_HTTP_CONTINUE)) { throw new IOException("Operation has already ended"); @@ -165,15 +157,14 @@ public final class ClientOperation implements Operation, BaseStream { } /** - * Retrieves the response code retrieved from the server. Response codes - * are defined in the <code>ResponseCodes</code> interface. - * + * Retrieves the response code retrieved from the server. Response codes are + * defined in the <code>ResponseCodes</code> interface. * @return the response code retrieved from the server - * * @throws IOException if an error occurred in the transport layer during - * the transaction; if this method is called on a <code>HeaderSet</code> - * object created by calling <code>createHeaderSet</code> in a - * <code>ClientSession</code> object + * the transaction; if this method is called on a + * <code>HeaderSet</code> object created by calling + * <code>createHeaderSet</code> in a <code>ClientSession</code> + * object */ public synchronized int getResponseCode() throws IOException { //avoid dup validateConnection @@ -187,7 +178,6 @@ public final class ClientOperation implements Operation, BaseStream { /** * This method will always return <code>null</code> - * * @return <code>null</code> */ public String getEncoding() { @@ -198,9 +188,8 @@ public final class ClientOperation implements Operation, BaseStream { * Returns the type of content that the resource connected to is providing. * E.g. if the connection is via HTTP, then the value of the content-type * header field is returned. - * * @return the content type of the resource that the URL references, or - * <code>null</code> if not known + * <code>null</code> if not known */ public String getType() { try { @@ -212,11 +201,10 @@ public final class ClientOperation implements Operation, BaseStream { /** * Returns the length of the content which is being provided. E.g. if the - * connection is via HTTP, then the value of the content-length header - * field is returned. - * + * connection is via HTTP, then the value of the content-length header field + * is returned. * @return the content length of the resource that this connection's URL - * references, or -1 if the content length is not known + * references, or -1 if the content length is not known */ public long getLength() { try { @@ -234,9 +222,7 @@ public final class ClientOperation implements Operation, BaseStream { /** * Open and return an input stream for a connection. - * * @return an input stream - * * @throws IOException if an I/O error occurs */ public InputStream openInputStream() throws IOException { @@ -259,11 +245,9 @@ public final class ClientOperation implements Operation, BaseStream { return mPrivateInput; } - /**8 + /** * Open and return a data input stream for a connection. - * * @return an input stream - * * @throws IOException if an I/O error occurs */ public DataInputStream openDataInputStream() throws IOException { @@ -272,9 +256,7 @@ public final class ClientOperation implements Operation, BaseStream { /** * Open and return an output stream for a connection. - * * @return an output stream - * * @throws IOException if an I/O error occurs */ public OutputStream openOutputStream() throws IOException { @@ -301,9 +283,7 @@ public final class ClientOperation implements Operation, BaseStream { /** * Open and return a data output stream for a connection. - * * @return an output stream - * * @throws IOException if an I/O error occurs */ public DataOutputStream openDataOutputStream() throws IOException { @@ -312,7 +292,6 @@ public final class ClientOperation implements Operation, BaseStream { /** * Closes the connection and ends the transaction - * * @throws IOException if the operation has already ended or is closed */ public void close() throws IOException { @@ -324,11 +303,9 @@ public final class ClientOperation implements Operation, BaseStream { /** * Returns the headers that have been received during the operation. - * Modifying the object returned has no effect on the headers that are - * sent or retrieved. - * + * Modifying the object returned has no effect on the headers that are sent + * or retrieved. * @return the headers received during this <code>Operation</code> - * * @throws IOException if this <code>Operation</code> has been closed */ public HeaderSet getReceivedHeader() throws IOException { @@ -340,15 +317,11 @@ public final class ClientOperation implements Operation, BaseStream { /** * Specifies the headers that should be sent in the next OBEX message that * is sent. - * * @param headers the headers to send in the next message - * - * @throws IOException if this <code>Operation</code> has been closed - * or the transaction has ended and no further messages will be exchanged - * + * @throws IOException if this <code>Operation</code> has been closed or the + * transaction has ended and no further messages will be exchanged * @throws IllegalArgumentException if <code>headers</code> was not created - * by a call to <code>ServerRequestHandler.createHeaderSet()</code> - * + * by a call to <code>ServerRequestHandler.createHeaderSet()</code> * @throws NullPointerException if <code>headers</code> is <code>null</code> */ public void sendHeaders(HeaderSet headers) throws IOException { @@ -370,62 +343,8 @@ public final class ClientOperation implements Operation, BaseStream { } /** - * Reads a response from the server. It will populate the appropriate body - * and headers. - * - * @return <code>true</code> if the transaction should end; - * <code>false</code> if the transaction should not end - * - * @throws IOException if an IO error occurred - */ - /* - private boolean readResponse() throws IOException { - mReplyHeader.responseCode = mInput.read(); - int packetLength = mInput.read(); - packetLength = (packetLength << 8) + mInput.read(); - - if (packetLength > ObexHelper.MAX_PACKET_SIZE_INT) { - if (mExceptionMessage != null) { - abort(); - } - throw new IOException("Received a packet that was too big"); - } - - if (packetLength > ObexHelper.BASE_PACKET_LENGTH) { - int dataLength = packetLength - ObexHelper.BASE_PACKET_LENGTH; - byte[] data = new byte[dataLength]; - int readLength = mInput.read(data); - if (readLength != dataLength) { - throw new IOException("Received a packet without data as decalred length"); - } - byte[] body = ObexHelper.updateHeaderSet(mReplyHeader, data); - - if (body != null) { - mPrivateInput.writeBytes(body, 1); - - /* - * Determine if a body (0x48) header or an end of body (0x49) - * was received. If we received an end of body and - * a response code of OBEX_HTTP_OK, then the operation should - * end. - * - if ((body[0] == 0x49) && (mReplyHeader.responseCode == ResponseCodes.OBEX_HTTP_OK)) { - return false; - } - } - } - - if (mReplyHeader.responseCode == ResponseCodes.OBEX_HTTP_CONTINUE) { - return true; - } else { - return false; - } - } - */ - /** - * Verifies that additional information may be sent. In other words, the + * Verifies that additional information may be sent. In other words, the * operation is not done. - * * @throws IOException if the operation is completed */ public void ensureNotDone() throws IOException { @@ -436,7 +355,6 @@ public final class ClientOperation implements Operation, BaseStream { /** * Verifies that the connection is open and no exceptions should be thrown. - * * @throws IOException if an exception needs to be thrown */ public void ensureOpen() throws IOException { @@ -452,7 +370,6 @@ public final class ClientOperation implements Operation, BaseStream { /** * Verifies that the connection is open and the proper data has been read. - * * @throws IOException if an IO error occurs */ private void validateConnection() throws IOException { @@ -466,15 +383,12 @@ public final class ClientOperation implements Operation, BaseStream { /** * Sends a request to the client of the specified type - * - * @param response the response code to send back to the client - * + * @param opCode the request code to send to the client * @return <code>true</code> if there is more data to send; - * <code>false</code> if there is no more data to send - * + * <code>false</code> if there is no more data to send * @throws IOException if an IO error occurs */ - private boolean sendRequest(int type) throws IOException { + private boolean sendRequest(int opCode) throws IOException { boolean returnValue = false; ByteArrayOutputStream out = new ByteArrayOutputStream(); int bodyLength = -1; @@ -519,7 +433,7 @@ public final class ClientOperation implements Operation, BaseStream { byte[] sendHeader = new byte[end - start]; System.arraycopy(headerArray, start, sendHeader, 0, sendHeader.length); - if (!mParent.sendRequest(type, sendHeader, mReplyHeader, mPrivateInput)) { + if (!mParent.sendRequest(opCode, sendHeader, mReplyHeader, mPrivateInput)) { return false; } @@ -559,7 +473,7 @@ public final class ClientOperation implements Operation, BaseStream { * (End of Body) otherwise, we need to send 0x48 (Body) */ if ((mPrivateOutput.isClosed()) && (!returnValue) && (!mEndOfBodySent) - && ((type & 0x80) != 0)) { + && ((opCode & 0x80) != 0)) { out.write(0x49); mEndOfBodySent = true; } else { @@ -577,7 +491,7 @@ public final class ClientOperation implements Operation, BaseStream { if (mPrivateOutputOpen && bodyLength <= 0 && !mEndOfBodySent) { // only 0x82 or 0x83 can send 0x49 - if ((type & 0x80) == 0) { + if ((opCode & 0x80) == 0) { out.write(0x48); } else { out.write(0x49); @@ -591,13 +505,13 @@ public final class ClientOperation implements Operation, BaseStream { } if (out.size() == 0) { - if (!mParent.sendRequest(type, null, mReplyHeader, mPrivateInput)) { + if (!mParent.sendRequest(opCode, null, mReplyHeader, mPrivateInput)) { return false; } return returnValue; } if ((out.size() > 0) - && (!mParent.sendRequest(type, out.toByteArray(), mReplyHeader, mPrivateInput))) { + && (!mParent.sendRequest(opCode, out.toByteArray(), mReplyHeader, mPrivateInput))) { return false; } @@ -610,10 +524,9 @@ public final class ClientOperation implements Operation, BaseStream { } /** - * This method starts the processing thread results. It will send the - * initial request. If the response takes more then one packet, a thread + * This method starts the processing thread results. It will send the + * initial request. If the response takes more then one packet, a thread * will be started to handle additional requests - * * @throws IOException if an IO error occurs */ private synchronized void startProcessing() throws IOException { @@ -659,11 +572,10 @@ public final class ClientOperation implements Operation, BaseStream { /** * Continues the operation since there is no data to read. - * - * @param sendEmpty <code>true</code> if the operation should send an - * empty packet or not send anything if there is no data to send - * @param inStream <code>true</code> if the stream is input stream or - * is output stream + * @param sendEmpty <code>true</code> if the operation should send an empty + * packet or not send anything if there is no data to send + * @param inStream <code>true</code> if the stream is input stream or is + * output stream * @throws IOException if an IO error occurs */ public synchronized boolean continueOperation(boolean sendEmpty, boolean inStream) @@ -717,10 +629,8 @@ public final class ClientOperation implements Operation, BaseStream { /** * Called when the output or input stream is closed. - * * @param inStream <code>true</code> if the input stream is closed; - * <code>false</code> if the output stream is closed - * + * <code>false</code> if the output stream is closed * @throws IOException if an IO error occurs */ public void streamClosed(boolean inStream) throws IOException { @@ -804,7 +714,6 @@ public final class ClientOperation implements Operation, BaseStream { if (mReplyHeader.responseCode != ResponseCodes.OBEX_HTTP_CONTINUE) { mOperationDone = true; } - } } } diff --git a/obex/javax/obex/ClientSession.java b/obex/javax/obex/ClientSession.java index d554922..0935383 100644 --- a/obex/javax/obex/ClientSession.java +++ b/obex/javax/obex/ClientSession.java @@ -39,7 +39,6 @@ import java.io.OutputStream; /** * This class in an implementation of the OBEX ClientSession. - * * @hide */ public final class ClientSession extends ObexSession { @@ -163,7 +162,7 @@ public final class ClientSession extends ObexSession { } /** - * 0xCB Connection Id an identifier used for OBEX connection multiplexing + * 0xCB Connection Id an identifier used for OBEX connection multiplexing */ public void setConnectionID(long id) { if ((id < 0) || (id > 0xFFFFFFFFL)) { @@ -365,7 +364,6 @@ public final class ClientSession extends ObexSession { /** * Verifies that the connection is open. - * * @throws IOException if the connection is closed */ public synchronized void ensureOpen() throws IOException { @@ -375,9 +373,8 @@ public final class ClientSession extends ObexSession { } /** - * Set request inactive. - * Allows Put and get operation objects to tell this object when they are - * done. + * Set request inactive. Allows Put and get operation objects to tell this + * object when they are done. */ /*package*/synchronized void setRequestInactive() { mRequestActive = false; @@ -395,27 +392,17 @@ public final class ClientSession extends ObexSession { } /** - * Sends a standard request to the client. It will then wait for the reply - * and update the header set object provided. If any authentication - * headers (i.e. authentication challenge or authentication response) are - * received, they will be processed. - * + * Sends a standard request to the client. It will then wait for the reply + * and update the header set object provided. If any authentication headers + * (i.e. authentication challenge or authentication response) are received, + * they will be processed. * @param opCode the type of request to send to the client - * - * @param head the headers to send to the server - * - * @param challenge the nonce that was sent in the authentication - * challenge header located in <code>head</code>; <code>null</code> - * if no authentication header is included in <code>head</code> - * + * @param head the headers to send to the client * @param header the header object to update with the response - * - * @param input the input stream used by the Operation object; null if this - * is called on a CONNECT, SETPATH or DISCONNECT - * - * return <code>true</code> if the operation completed successfully; - * <code>false</code> if an authentication response failed to pass - * + * @param privateInput the input stream used by the Operation object; null + * if this is called on a CONNECT, SETPATH or DISCONNECT return + * <code>true</code> if the operation completed successfully; + * <code>false</code> if an authentication response failed to pass * @throws IOException if an IO error occurs */ public boolean sendRequest(int opCode, byte[] head, HeaderSet header, diff --git a/obex/javax/obex/HeaderSet.java b/obex/javax/obex/HeaderSet.java index f777da6..8b457f6 100644 --- a/obex/javax/obex/HeaderSet.java +++ b/obex/javax/obex/HeaderSet.java @@ -40,28 +40,27 @@ import java.util.Random; /** * This class implements the javax.obex.HeaderSet interface for OBEX over * RFCOMM. - * * @hide */ public final class HeaderSet { /** - * Represents the OBEX Count header. This allows the connection statement - * to tell the server how many objects it plans to send or retrieve. + * Represents the OBEX Count header. This allows the connection statement to + * tell the server how many objects it plans to send or retrieve. * <P> * The value of <code>COUNT</code> is 0xC0 (192). */ public static final int COUNT = 0xC0; /** - * Represents the OBEX Name header. This specifies the name of the object. + * Represents the OBEX Name header. This specifies the name of the object. * <P> * The value of <code>NAME</code> is 0x01 (1). */ public static final int NAME = 0x01; /** - * Represents the OBEX Type header. This allows a request to specify the + * Represents the OBEX Type header. This allows a request to specify the * type of the object (e.g. text, html, binary, etc.). * <P> * The value of <code>TYPE</code> is 0x42 (66). @@ -69,7 +68,7 @@ public final class HeaderSet { public static final int TYPE = 0x42; /** - * Represents the OBEX Length header. This is the length of the object in + * Represents the OBEX Length header. This is the length of the object in * bytes. * <P> * The value of <code>LENGTH</code> is 0xC3 (195). @@ -77,32 +76,32 @@ public final class HeaderSet { public static final int LENGTH = 0xC3; /** - * Represents the OBEX Time header using the ISO 8601 standards. This is - * the preferred time header. + * Represents the OBEX Time header using the ISO 8601 standards. This is the + * preferred time header. * <P> * The value of <code>TIME_ISO_8601</code> is 0x44 (68). */ public static final int TIME_ISO_8601 = 0x44; /** - * Represents the OBEX Time header using the 4 byte representation. This - * is only included for backwards compatibility. It represents the number - * of seconds since January 1, 1970. + * Represents the OBEX Time header using the 4 byte representation. This is + * only included for backwards compatibility. It represents the number of + * seconds since January 1, 1970. * <P> * The value of <code>TIME_4_BYTE</code> is 0xC4 (196). */ public static final int TIME_4_BYTE = 0xC4; /** - * Represents the OBEX Description header. This is a text description of - * the object. + * Represents the OBEX Description header. This is a text description of the + * object. * <P> * The value of <code>DESCRIPTION</code> is 0x05 (5). */ public static final int DESCRIPTION = 0x05; /** - * Represents the OBEX Target header. This is the name of the service an + * Represents the OBEX Target header. This is the name of the service an * operation is targeted to. * <P> * The value of <code>TARGET</code> is 0x46 (70). @@ -110,7 +109,7 @@ public final class HeaderSet { public static final int TARGET = 0x46; /** - * Represents the OBEX HTTP header. This allows an HTTP 1.X header to be + * Represents the OBEX HTTP header. This allows an HTTP 1.X header to be * included in a request or reply. * <P> * The value of <code>HTTP</code> is 0x47 (71). @@ -132,7 +131,7 @@ public final class HeaderSet { public static final int END_OF_BODY = 0x49; /** - * Represents the OBEX Who header. Identifies the OBEX application to + * Represents the OBEX Who header. Identifies the OBEX application to * determine if the two peers are talking to each other. * <P> * The value of <code>WHO</code> is 0x4A (74). @@ -149,7 +148,7 @@ public final class HeaderSet { public static final int CONNECTION_ID = 0xCB; /** - * Represents the OBEX Application Parameter header. This header specifies + * Represents the OBEX Application Parameter header. This header specifies * additional application request and response information. * <P> * The value of <code>APPLICATION_PARAMETER</code> is 0x4C (76). @@ -171,8 +170,8 @@ public final class HeaderSet { public static final int AUTH_RESPONSE = 0x4E; /** - * Represents the OBEX Object Class header. This header specifies the - * OBEX object class of the object. + * Represents the OBEX Object Class header. This header specifies the OBEX + * object class of the object. * <P> * The value of <code>OBJECT_CLASS</code> is 0x4F (79). */ @@ -200,12 +199,6 @@ public final class HeaderSet { private byte[] mAppParam; // byte sequence of the form tag length value - public byte[] mAuthChall; // The authentication challenge header - - public byte[] mAuthResp; // The authentication response header - - public byte[] mConnectionID; // THe connection ID - private byte[] mObjectClass; // byte sequence private String[] mUnicodeUserDefined; //null terminated unicode string @@ -216,15 +209,20 @@ public final class HeaderSet { private Long[] mIntegerUserDefined; // 4 byte unsigned integer - /*package*/int responseCode; + private final Random mRandom; - /*package*/byte[] nonce; + /*package*/ byte[] nonce; - private final Random mRandom; + public byte[] mAuthChall; // The authentication challenge header + + public byte[] mAuthResp; // The authentication response header + + public byte[] mConnectionID; // THe connection ID + + public int responseCode; /** * Creates new <code>HeaderSet</code> object. - * * @param size the max packet size for this connection */ public HeaderSet() { @@ -237,20 +235,17 @@ public final class HeaderSet { } /** - * Sets the value of the header identifier to the value provided. The type + * Sets the value of the header identifier to the value provided. The type * of object must correspond to the Java type defined in the description of - * this interface. If <code>null</code> is passed as the + * this interface. If <code>null</code> is passed as the * <code>headerValue</code> then the header will be removed from the set of * headers to include in the next request. - * * @param headerID the identifier to include in the message - * * @param headerValue the value of the header identifier - * - * @throws IllegalArgumentException if the header identifier provided is - * not one defined in this interface or a user-defined header; if the type of - * <code>headerValue</code> is not the correct Java type as defined in the - * description of this interface\ + * @throws IllegalArgumentException if the header identifier provided is not + * one defined in this interface or a user-defined header; if the + * type of <code>headerValue</code> is not the correct Java type as + * defined in the description of this interface\ */ public void setHeader(int headerID, Object headerValue) { long temp = -1; @@ -435,20 +430,16 @@ public final class HeaderSet { } /** - * Retrieves the value of the header identifier provided. The type of the + * Retrieves the value of the header identifier provided. The type of the * Object returned is defined in the description of this interface. - * * @param headerID the header identifier whose value is to be returned - * * @return the value of the header provided or <code>null</code> if the - * header identifier specified is not part of this <code>HeaderSet</code> - * object - * - * @throws IllegalArgumentException if the <code>headerID</code> is not - * one defined in this interface or any of the user-defined headers - * + * header identifier specified is not part of this + * <code>HeaderSet</code> object + * @throws IllegalArgumentException if the <code>headerID</code> is not one + * defined in this interface or any of the user-defined headers * @throws IOException if an error occurred in the transport layer during - * the operation or if the connection has been closed + * the operation or if the connection has been closed */ public Object getHeader(int headerID) throws IOException { @@ -500,17 +491,14 @@ public final class HeaderSet { /** * Retrieves the list of headers that may be retrieved via the - * <code>getHeader</code> method that will not return <code>null</code>. - * In other words, this method returns all the headers that are available - * in this object. - * + * <code>getHeader</code> method that will not return <code>null</code>. In + * other words, this method returns all the headers that are available in + * this object. * @see #getHeader - * * @return the array of headers that are set in this object or - * <code>null</code> if no headers are available - * + * <code>null</code> if no headers are available * @throws IOException if an error occurred in the transport layer during - * the operation or the connection has been closed + * the operation or the connection has been closed */ public int[] getHeaderList() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -594,51 +582,41 @@ public final class HeaderSet { } /** - * Sets the authentication challenge header. The <code>realm</code> will - * be encoded based upon the default encoding scheme used by the - * implementation to encode strings. Therefore, the encoding scheme used - * to encode the <code>realm</code> is application dependent. - * + * Sets the authentication challenge header. The <code>realm</code> will be + * encoded based upon the default encoding scheme used by the implementation + * to encode strings. Therefore, the encoding scheme used to encode the + * <code>realm</code> is application dependent. * @param realm a short description that describes what password to use; if - * <code>null</code> no realm will be sent in the authentication challenge - * header - * + * <code>null</code> no realm will be sent in the authentication + * challenge header * @param userID if <code>true</code>, a user ID is required in the reply; - * if <code>false</code>, no user ID is required - * + * if <code>false</code>, no user ID is required * @param access if <code>true</code> then full access will be granted if - * successful; if <code>false</code> then read-only access will be granted - * if successful + * successful; if <code>false</code> then read-only access will be + * granted if successful * @throws IOException */ public void createAuthenticationChallenge(String realm, boolean userID, boolean access) throws IOException { - try { - nonce = new byte[16]; - for (int i = 0; i < 16; i++) { - nonce[i] = (byte)mRandom.nextInt(); - } - - mAuthChall = ObexHelper.computeAuthenticationChallenge(nonce, realm, access, userID); - } catch (IOException e) { - throw e; + nonce = new byte[16]; + for (int i = 0; i < 16; i++) { + nonce[i] = (byte)mRandom.nextInt(); } + + mAuthChall = ObexHelper.computeAuthenticationChallenge(nonce, realm, access, userID); } /** - * Returns the response code received from the server. Response codes - * are defined in the <code>ResponseCodes</code> class. - * + * Returns the response code received from the server. Response codes are + * defined in the <code>ResponseCodes</code> class. * @see ResponseCodes - * * @return the response code retrieved from the server - * * @throws IOException if an error occurred in the transport layer during - * the transaction; if this method is called on a <code>HeaderSet</code> - * object created by calling <code>createHeaderSet()</code> in a - * <code>ClientSession</code> object; if this object was created by an OBEX - * server + * the transaction; if this method is called on a + * <code>HeaderSet</code> object created by calling + * <code>createHeaderSet()</code> in a <code>ClientSession</code> + * object; if this object was created by an OBEX server */ public int getResponseCode() throws IOException { if (responseCode == -1) { diff --git a/obex/javax/obex/ObexHelper.java b/obex/javax/obex/ObexHelper.java index 511b7c6..e6ade7b 100644 --- a/obex/javax/obex/ObexHelper.java +++ b/obex/javax/obex/ObexHelper.java @@ -43,16 +43,14 @@ import java.util.TimeZone; /** * This class defines a set of helper methods for the implementation of Obex. - * * @hide */ public final class ObexHelper { /** - * Defines the basic packet length used by OBEX. Every OBEX packet has the + * Defines the basic packet length used by OBEX. Every OBEX packet has the * same basic format:<BR> - * Byte 0: Request or Response Code - * Byte 1&2: Length of the packet. + * Byte 0: Request or Response Code Byte 1&2: Length of the packet. */ public static final int BASE_PACKET_LENGTH = 3; @@ -61,17 +59,14 @@ public final class ObexHelper { } /** - * The maximum packet size for OBEX packets that this client can handle. - * At present, this must be changed for each port. - * - * TODO: The max packet size should be the Max incoming MTU minus - * TODO: L2CAP package headers and RFCOMM package headers. - * - * TODO: Retrieve the max incoming MTU from - * TODO: LocalDevice.getProperty(). + * The maximum packet size for OBEX packets that this client can handle. At + * present, this must be changed for each port. TODO: The max packet size + * should be the Max incoming MTU minus TODO: L2CAP package headers and + * RFCOMM package headers. TODO: Retrieve the max incoming MTU from TODO: + * LocalDevice.getProperty(). */ - /** android note - * set as 0xFFFE to match remote MPS + /* + * android note set as 0xFFFE to match remote MPS */ public static final int MAX_PACKET_SIZE_INT = 0xFFFE; @@ -119,34 +114,46 @@ public final class ObexHelper { /** * Updates the HeaderSet with the headers received in the byte array - * provided. Invalid headers are ignored. + * provided. Invalid headers are ignored. * <P> - * The first two bits of an OBEX Header specifies the type of object that - * is being sent. The table below specifies the meaning of the high - * bits. + * The first two bits of an OBEX Header specifies the type of object that is + * being sent. The table below specifies the meaning of the high bits. * <TABLE> - * <TR><TH>Bits 8 and 7</TH><TH>Value</TH><TH>Description</TH></TR> - * <TR><TD>00</TD><TD>0x00</TD><TD>Null Terminated Unicode text, prefixed - * with 2 byte unsigned integer</TD></TR> - * <TR><TD>01</TD><TD>0x40</TD><TD>Byte Sequence, length prefixed with - * 2 byte unsigned integer</TD></TR> - * <TR><TD>10</TD><TD>0x80</TD><TD>1 byte quantity</TD></TR> - * <TR><TD>11</TD><TD>0xC0</TD><TD>4 byte quantity - transmitted in - * network byte order (high byte first</TD></TR> + * <TR> + * <TH>Bits 8 and 7</TH> + * <TH>Value</TH> + * <TH>Description</TH> + * </TR> + * <TR> + * <TD>00</TD> + * <TD>0x00</TD> + * <TD>Null Terminated Unicode text, prefixed with 2 byte unsigned integer</TD> + * </TR> + * <TR> + * <TD>01</TD> + * <TD>0x40</TD> + * <TD>Byte Sequence, length prefixed with 2 byte unsigned integer</TD> + * </TR> + * <TR> + * <TD>10</TD> + * <TD>0x80</TD> + * <TD>1 byte quantity</TD> + * </TR> + * <TR> + * <TD>11</TD> + * <TD>0xC0</TD> + * <TD>4 byte quantity - transmitted in network byte order (high byte first</TD> + * </TR> * </TABLE> * This method uses the information in this table to determine the type of - * Java object to create and passes that object with the full header - * to setHeader() to update the HeaderSet object. Invalid headers will - * cause an exception to be thrown. When it is thrown, it is ignored. - * + * Java object to create and passes that object with the full header to + * setHeader() to update the HeaderSet object. Invalid headers will cause an + * exception to be thrown. When it is thrown, it is ignored. * @param header the HeaderSet to update - * * @param headerArray the byte array containing headers - * * @return the result of the last start body or end body header provided; - * the first byte in the result will specify if a body or end of body is - * received - * + * the first byte in the result will specify if a body or end of + * body is received * @throws IOException if an invalid header was found */ public static byte[] updateHeaderSet(HeaderSet header, byte[] headerArray) throws IOException { @@ -316,18 +323,13 @@ public final class ObexHelper { /** * Creates the header part of OBEX packet based on the header provided. - * - * TODO: Could use getHeaderList() to get the array of headers to - * TODO: include and then use the high two bits to determine the - * TODO: the type of the object and construct the byte array from - * TODO: that. This will make the size smaller. - * + * TODO: Could use getHeaderList() to get the array of headers to include + * and then use the high two bits to determine the the type of the object + * and construct the byte array from that. This will make the size smaller. * @param head the header used to construct the byte array - * * @param nullOut <code>true</code> if the header should be set to - * <code>null</code> once it is added to the array or <code>false</code> - * if it should not be nulled out - * + * <code>null</code> once it is added to the array or + * <code>false</code> if it should not be nulled out * @return the header of an OBEX packet */ public static byte[] createHeader(HeaderSet head, boolean nullOut) { @@ -342,9 +344,6 @@ public final class ObexHelper { int length; HeaderSet headImpl = null; ByteArrayOutputStream out = new ByteArrayOutputStream(); - if (!(head instanceof HeaderSet)) { - throw new IllegalArgumentException("Header not created by createHeaderSet"); - } headImpl = head; try { @@ -675,18 +674,14 @@ public final class ObexHelper { } /** - * Determines where the maximum divide is between headers. This method is + * Determines where the maximum divide is between headers. This method is * used by put and get operations to separate headers to a size that meets * the max packet size allowed. - * * @param headerArray the headers to separate - * * @param start the starting index to search - * * @param maxSize the maximum size of a packet - * * @return the index of the end of the header block to send or -1 if the - * header could not be divided because the header is too large + * header could not be divided because the header is too large */ public static int findHeaderEnd(byte[] headerArray, int start, int maxSize) { @@ -757,9 +752,7 @@ public final class ObexHelper { /** * Converts the byte array to a long. - * * @param b the byte array to convert to a long - * * @return the byte array as a long */ public static long convertToLong(byte[] b) { @@ -781,10 +774,8 @@ public final class ObexHelper { } /** - * Converts the long to a 4 byte array. The long must be non negative. - * + * Converts the long to a 4 byte array. The long must be non negative. * @param l the long to convert - * * @return a byte array that is the same as the long */ public static byte[] convertToByteArray(long l) { @@ -799,11 +790,9 @@ public final class ObexHelper { } /** - * Converts the String to a UNICODE byte array. It will also add the ending + * Converts the String to a UNICODE byte array. It will also add the ending * null characters to the end of the string. - * * @param s the string to convert - * * @return the unicode byte array of the string */ public static byte[] convertToUnicodeByteArray(String s) { @@ -826,13 +815,10 @@ public final class ObexHelper { } /** - * Retrieves the value from the byte array for the tag value specified. The + * Retrieves the value from the byte array for the tag value specified. The * array should be of the form Tag - Length - Value triplet. - * * @param tag the tag to retrieve from the byte array - * * @param triplet the byte sequence containing the tag length value form - * * @return the value of the specified tag */ public static byte[] getTagValue(byte tag, byte[] triplet) { @@ -854,11 +840,8 @@ public final class ObexHelper { /** * Finds the index that starts the tag value pair in the byte array provide. - * * @param tag the tag to look for - * * @param value the byte array to search - * * @return the starting index of the tag or -1 if the tag could not be found */ public static int findTag(byte tag, byte[] value) { @@ -884,16 +867,12 @@ public final class ObexHelper { /** * Converts the byte array provided to a unicode string. - * * @param b the byte array to convert to a string - * * @param includesNull determine if the byte string provided contains the - * UNICODE null character at the end or not; if it does, it will be - * removed - * + * UNICODE null character at the end or not; if it does, it will be + * removed * @return a Unicode string - * - * @param IllegalArgumentException if the byte array has an odd length + * @throws IllegalArgumentException if the byte array has an odd length */ public static String convertToUnicode(byte[] b, boolean includesNull) { if (b == null) { @@ -926,9 +905,8 @@ public final class ObexHelper { } /** - * Compute the MD5 hash of the byte array provided. - * Does not accumulate input. - * + * Compute the MD5 hash of the byte array provided. Does not accumulate + * input. * @param in the byte array to hash * @return the MD5 hash of the byte array */ @@ -939,23 +917,16 @@ public final class ObexHelper { /** * Computes an authentication challenge header. - * - * - * @param nonce the challenge that will be provided to the peer; the - * challenge must be 16 bytes long - * + * @param nonce the challenge that will be provided to the peer; the + * challenge must be 16 bytes long * @param realm a short description that describes what password to use - * * @param access if <code>true</code> then full access will be granted if - * successful; if <code>false</code> then read only access will be granted - * if successful - * + * successful; if <code>false</code> then read only access will be + * granted if successful * @param userID if <code>true</code>, a user ID is required in the reply; - * if <code>false</code>, no user ID is required - * - * @throws IllegalArgumentException if the challenge is not 16 bytes - * long; if the realm can not be encoded in less then 255 bytes - * + * if <code>false</code>, no user ID is required + * @throws IllegalArgumentException if the challenge is not 16 bytes long; + * if the realm can not be encoded in less then 255 bytes * @throws IOException if the encoding scheme ISO 8859-1 is not supported */ public static byte[] computeAuthenticationChallenge(byte[] nonce, String realm, boolean access, diff --git a/obex/javax/obex/ObexSession.java b/obex/javax/obex/ObexSession.java index 97d65e0..a7daeb5 100644 --- a/obex/javax/obex/ObexSession.java +++ b/obex/javax/obex/ObexSession.java @@ -41,10 +41,8 @@ import java.io.IOException; * of the same connection, which is established by server's accepting of a * client issued "CONNECT". * <P> - * * This interface serves as the common super class for * <CODE>ClientSession</CODE> and <CODE>ServerSession</CODE>. - * * @hide */ public class ObexSession { @@ -56,10 +54,7 @@ public class ObexSession { /** * Called when the server received an authentication challenge header. This * will cause the authenticator to handle the authentication challenge. - * - * @param header - * the header with the authentication challenge - * + * @param header the header with the authentication challenge * @return <code>true</code> if the last request should be resent; * <code>false</code> if the last request should not be resent * @throws IOException @@ -188,10 +183,7 @@ public class ObexSession { /** * Called when the server received an authentication response header. This * will cause the authenticator to handle the authentication response. - * - * @param authResp - * the authentication response - * + * @param authResp the authentication response * @return <code>true</code> if the response passed; <code>false</code> if * the response failed */ diff --git a/obex/javax/obex/ObexTransport.java b/obex/javax/obex/ObexTransport.java index d0ba0c9..445e267 100644 --- a/obex/javax/obex/ObexTransport.java +++ b/obex/javax/obex/ObexTransport.java @@ -51,7 +51,6 @@ import java.io.OutputStream; * Different kind of medium may have different construction - for example, the * RFCOMM device file medium may be constructed from a file descriptor or simply * a string while the TCP medium usually from a socket. - * * @hide */ public interface ObexTransport { diff --git a/obex/javax/obex/Operation.java b/obex/javax/obex/Operation.java index f265f53..20653f2 100644 --- a/obex/javax/obex/Operation.java +++ b/obex/javax/obex/Operation.java @@ -40,44 +40,39 @@ import java.io.OutputStream; /** * The <code>Operation</code> interface provides ways to manipulate a single - * OBEX PUT or GET operation. The implementation of this interface sends - * OBEX packets as they are built. If during the operation the peer in the - * operation ends the operation, an <code>IOException</code> is thrown on - * the next read from the input stream, write to the output stream, or call to + * OBEX PUT or GET operation. The implementation of this interface sends OBEX + * packets as they are built. If during the operation the peer in the operation + * ends the operation, an <code>IOException</code> is thrown on the next read + * from the input stream, write to the output stream, or call to * <code>sendHeaders()</code>. * <P> - * <STRONG>Definition of methods inherited from <code>ContentConnection</code></STRONG> + * <STRONG>Definition of methods inherited from <code>ContentConnection</code> + * </STRONG> * <P> - * <code>getEncoding()</code> will always return <code>null</code>. - * <BR><code>getLength()</code> will return the length specified by the OBEX Length - * header or -1 if the OBEX Length header was not included. - * <BR><code>getType()</code> will return the value specified in the OBEX Type + * <code>getEncoding()</code> will always return <code>null</code>. <BR> + * <code>getLength()</code> will return the length specified by the OBEX Length + * header or -1 if the OBEX Length header was not included. <BR> + * <code>getType()</code> will return the value specified in the OBEX Type * header or <code>null</code> if the OBEX Type header was not included.<BR> * <P> * <STRONG>How Headers are Handled</STRONG> * <P> * As headers are received, they may be retrieved through the - * <code>getReceivedHeaders()</code> method. If new headers are set during the + * <code>getReceivedHeaders()</code> method. If new headers are set during the * operation, the new headers will be sent during the next packet exchange. * <P> * <STRONG>PUT example</STRONG> * <P> * <PRE> - * void putObjectViaOBEX(ClientSession conn, HeaderSet head, byte[] obj) - * throws IOException { - * + * void putObjectViaOBEX(ClientSession conn, HeaderSet head, byte[] obj) throws IOException { * // Include the length header * head.setHeader(head.LENGTH, new Long(obj.length)); - * * // Initiate the PUT request * Operation op = conn.put(head); - * * // Open the output stream to put the object to it * DataOutputStream out = op.openDataOutputStream(); - * * // Send the object to the server * out.write(obj); - * * // End the transaction * out.close(); * op.close(); @@ -88,64 +83,55 @@ import java.io.OutputStream; * <P> * <PRE> * byte[] getObjectViaOBEX(ClientSession conn, HeaderSet head) throws IOException { - * * // Send the initial GET request to the server * Operation op = conn.get(head); - * * // Retrieve the length of the object being sent back * int length = op.getLength(); - * - * // Create space for the object - * byte[] obj = new byte[length]; - * + * // Create space for the object + * byte[] obj = new byte[length]; * // Get the object from the input stream * DataInputStream in = trans.openDataInputStream(); * in.read(obj); - * * // End the transaction * in.close(); * op.close(); - * * return obj; * } * </PRE> - * <H3>Client PUT Operation Flow</H3> - * For PUT operations, a call to <code>close()</code> the <code>OutputStream</code> - * returned from <code>openOutputStream()</code> or <code>openDataOutputStream()</code> - * will signal that the request is done. (In OBEX terms, the End-Of-Body header should - * be sent and the final bit in the request will be set.) At this point, the - * reply from the server may begin to be processed. A call to + * + * <H3>Client PUT Operation Flow</H3> For PUT operations, a call to + * <code>close()</code> the <code>OutputStream</code> returned from + * <code>openOutputStream()</code> or <code>openDataOutputStream()</code> will + * signal that the request is done. (In OBEX terms, the End-Of-Body header + * should be sent and the final bit in the request will be set.) At this point, + * the reply from the server may begin to be processed. A call to * <code>getResponseCode()</code> will do an implicit close on the * <code>OutputStream</code> and therefore signal that the request is done. - * <H3>Client GET Operation Flow</H3> - * For GET operation, a call to <code>openInputStream()</code> or - * <code>openDataInputStream()</code> will signal that the request is done. (In OBEX - * terms, the final bit in the request will be set.) A call to - * <code>getResponseCode()</code> will cause an implicit close on the - * <code>InputStream</code>. No further data may be read at this point. - * + * <H3>Client GET Operation Flow</H3> For GET operation, a call to + * <code>openInputStream()</code> or <code>openDataInputStream()</code> will + * signal that the request is done. (In OBEX terms, the final bit in the request + * will be set.) A call to <code>getResponseCode()</code> will cause an implicit + * close on the <code>InputStream</code>. No further data may be read at this + * point. * @hide */ public interface Operation { /** - * Sends an ABORT message to the server. By calling this method, the + * Sends an ABORT message to the server. By calling this method, the * corresponding input and output streams will be closed along with this - * object. No headers are sent in the abort request. This will end the + * object. No headers are sent in the abort request. This will end the * operation since <code>close()</code> will be called by this method. - * - * @throws IOException if the transaction has already ended or if an - * OBEX server calls this method + * @throws IOException if the transaction has already ended or if an OBEX + * server calls this method */ void abort() throws IOException; /** * Returns the headers that have been received during the operation. - * Modifying the object returned has no effect on the headers that are - * sent or retrieved. - * + * Modifying the object returned has no effect on the headers that are sent + * or retrieved. * @return the headers received during this <code>Operation</code> - * * @throws IOException if this <code>Operation</code> has been closed */ HeaderSet getReceivedHeader() throws IOException; @@ -153,30 +139,23 @@ public interface Operation { /** * Specifies the headers that should be sent in the next OBEX message that * is sent. - * * @param headers the headers to send in the next message - * - * @throws IOException if this <code>Operation</code> has been closed - * or the transaction has ended and no further messages will be exchanged - * + * @throws IOException if this <code>Operation</code> has been closed or the + * transaction has ended and no further messages will be exchanged * @throws IllegalArgumentException if <code>headers</code> was not created - * by a call to <code>ServerRequestHandler.createHeaderSet()</code> or - * <code>ClientSession.createHeaderSet()</code> - * + * by a call to <code>ServerRequestHandler.createHeaderSet()</code> + * or <code>ClientSession.createHeaderSet()</code> * @throws NullPointerException if <code>headers</code> if <code>null</code> */ void sendHeaders(HeaderSet headers) throws IOException; /** - * Returns the response code received from the server. Response codes - * are defined in the <code>ResponseCodes</code> class. - * + * Returns the response code received from the server. Response codes are + * defined in the <code>ResponseCodes</code> class. * @see ResponseCodes - * * @return the response code retrieved from the server - * * @throws IOException if an error occurred in the transport layer during - * the transaction; if this object was created by an OBEX server + * the transaction; if this object was created by an OBEX server */ int getResponseCode() throws IOException; diff --git a/obex/javax/obex/PasswordAuthentication.java b/obex/javax/obex/PasswordAuthentication.java index e81a861..326b1ff 100644 --- a/obex/javax/obex/PasswordAuthentication.java +++ b/obex/javax/obex/PasswordAuthentication.java @@ -34,7 +34,6 @@ package javax.obex; /** * This class holds user name and password combinations. - * * @hide */ public final class PasswordAuthentication { @@ -44,15 +43,12 @@ public final class PasswordAuthentication { private final byte[] mPassword; /** - * Creates a new <code>PasswordAuthentication</code> with the user name - * and password provided. - * + * Creates a new <code>PasswordAuthentication</code> with the user name and + * password provided. * @param userName the user name to include; this may be <code>null</code> - * * @param password the password to include in the response - * * @throws NullPointerException if <code>password</code> is - * <code>null</code> + * <code>null</code> */ public PasswordAuthentication(final byte[] userName, final byte[] password) { if (userName != null) { @@ -65,9 +61,8 @@ public final class PasswordAuthentication { } /** - * Retrieves the user name that was specified in the constructor. - * The user name may be <code>null</code>. - * + * Retrieves the user name that was specified in the constructor. The user + * name may be <code>null</code>. * @return the user name */ public byte[] getUserName() { @@ -76,7 +71,6 @@ public final class PasswordAuthentication { /** * Retrieves the password. - * * @return the password */ public byte[] getPassword() { diff --git a/obex/javax/obex/PrivateInputStream.java b/obex/javax/obex/PrivateInputStream.java index 2dc02da..5daee72 100644 --- a/obex/javax/obex/PrivateInputStream.java +++ b/obex/javax/obex/PrivateInputStream.java @@ -38,7 +38,6 @@ import java.io.IOException; /** * This object provides an input stream to the Operation objects used in this * package. - * * @hide */ public final class PrivateInputStream extends InputStream { @@ -53,7 +52,6 @@ public final class PrivateInputStream extends InputStream { /** * Creates an input stream for the <code>Operation</code> to read from - * * @param p the connection this input stream is for */ public PrivateInputStream(BaseStream p) { @@ -68,10 +66,8 @@ public final class PrivateInputStream extends InputStream { * input stream without blocking by the next caller of a method for this * input stream. The next caller might be the same thread or or another * thread. - * * @return the number of bytes that can be read from this input stream - * without blocking - * + * without blocking * @throws IOException if an I/O error occurs */ @Override @@ -82,14 +78,12 @@ public final class PrivateInputStream extends InputStream { /** * Reads the next byte of data from the input stream. The value byte is - * returned as an int in the range 0 to 255. If no byte is available - * because the end of the stream has been reached, the value -1 is - * returned. This method blocks until input data is available, the end of - * the stream is detected, or an exception is thrown. - * - * @return the byte read from the input stream or -1 if it reaches the end - * of stream - * + * returned as an int in the range 0 to 255. If no byte is available because + * the end of the stream has been reached, the value -1 is returned. This + * method blocks until input data is available, the end of the stream is + * detected, or an exception is thrown. + * @return the byte read from the input stream or -1 if it reaches the end of + * stream * @throws IOException if an I/O error occurs */ @Override @@ -147,9 +141,7 @@ public final class PrivateInputStream extends InputStream { /** * Allows the <code>OperationImpl</code> thread to add body data to the * input stream. - * * @param body the data to add to the stream - * * @param start the start of the body to array to copy */ public synchronized void writeBytes(byte[] body, int start) { @@ -167,7 +159,6 @@ public final class PrivateInputStream extends InputStream { /** * Verifies that this stream is open - * * @throws IOException if the stream is not open */ private void ensureOpen() throws IOException { @@ -178,9 +169,8 @@ public final class PrivateInputStream extends InputStream { } /** - * Closes the input stream. If the input stream is already closed, do + * Closes the input stream. If the input stream is already closed, do * nothing. - * * @throws IOException this will never happen */ @Override diff --git a/obex/javax/obex/PrivateOutputStream.java b/obex/javax/obex/PrivateOutputStream.java index d972f78..ca420af 100644 --- a/obex/javax/obex/PrivateOutputStream.java +++ b/obex/javax/obex/PrivateOutputStream.java @@ -39,7 +39,6 @@ import java.io.ByteArrayOutputStream; /** * This object provides an output stream to the Operation objects used in this * package. - * * @hide */ public final class PrivateOutputStream extends OutputStream { @@ -54,18 +53,17 @@ public final class PrivateOutputStream extends OutputStream { /** * Creates an empty <code>PrivateOutputStream</code> to write to. - * * @param p the connection that this stream runs over */ public PrivateOutputStream(BaseStream p, int maxSize) { mParent = p; mArray = new ByteArrayOutputStream(); mMaxPacketSize = maxSize; + mOpen = true; } /** * Determines how many bytes have been written to the output stream. - * * @return the number of bytes written to the output stream */ public int size() { @@ -73,13 +71,11 @@ public final class PrivateOutputStream extends OutputStream { } /** - * Writes the specified byte to this output stream. The general contract - * for write is that one byte is written to the output stream. The byte to - * be written is the eight low-order bits of the argument b. The 24 - * high-order bits of b are ignored. - * + * Writes the specified byte to this output stream. The general contract for + * write is that one byte is written to the output stream. The byte to be + * written is the eight low-order bits of the argument b. The 24 high-order + * bits of b are ignored. * @param b the byte to write - * * @throws IOException if an I/O error occurs */ @Override @@ -128,9 +124,7 @@ public final class PrivateOutputStream extends OutputStream { /** * Reads the bytes that have been written to this stream. - * * @param size the size of the array to return - * * @return the byte array that is written */ public synchronized byte[] readBytes(int size) { @@ -150,7 +144,6 @@ public final class PrivateOutputStream extends OutputStream { /** * Verifies that this stream is open - * * @throws IOException if the stream is not open */ private void ensureOpen() throws IOException { @@ -161,9 +154,8 @@ public final class PrivateOutputStream extends OutputStream { } /** - * Closes the output stream. If the input stream is already closed, do + * Closes the output stream. If the input stream is already closed, do * nothing. - * * @throws IOException this will never happen */ @Override @@ -174,9 +166,8 @@ public final class PrivateOutputStream extends OutputStream { /** * Determines if the connection is closed - * - * @return <code>true</code> if the connection is closed; - * <code>false</code> if the connection is open + * @return <code>true</code> if the connection is closed; <code>false</code> + * if the connection is open */ public boolean isClosed() { return !mOpen; diff --git a/obex/javax/obex/ResponseCodes.java b/obex/javax/obex/ResponseCodes.java index f6cc9c1..a2b9a37 100644 --- a/obex/javax/obex/ResponseCodes.java +++ b/obex/javax/obex/ResponseCodes.java @@ -33,8 +33,8 @@ package javax.obex; /** - * The <code>ResponseCodes</code> class contains the list of valid - * response codes a server may send to a client. + * The <code>ResponseCodes</code> class contains the list of valid response + * codes a server may send to a client. * <P> * <STRONG>IMPORTANT NOTE</STRONG> * <P> @@ -42,13 +42,12 @@ package javax.obex; * specification, which is different with the HTTP specification. * <P> * <code>OBEX_DATABASE_FULL</code> and <code>OBEX_DATABASE_LOCKED</code> require - * further description since they are not defined in HTTP. The server will send + * further description since they are not defined in HTTP. The server will send * an <code>OBEX_DATABASE_FULL</code> message when the client requests that * something be placed into a database but the database is full (cannot take - * more data). <code>OBEX_DATABASE_LOCKED</code> will be returned when the + * more data). <code>OBEX_DATABASE_LOCKED</code> will be returned when the * client wishes to access a database, database table, or database record that * has been locked. - * * @hide */ public final class ResponseCodes { diff --git a/obex/javax/obex/ServerOperation.java b/obex/javax/obex/ServerOperation.java index 6c3d9ba..8710c64 100644 --- a/obex/javax/obex/ServerOperation.java +++ b/obex/javax/obex/ServerOperation.java @@ -42,18 +42,14 @@ import java.io.ByteArrayOutputStream; /** * This class implements the Operation interface for server side connections. * <P> - * <STRONG>Request Codes</STRONG> - * There are four different request codes that are in this class. 0x02 is a - * PUT request that signals that the request is not complete and requires an - * additional OBEX packet. 0x82 is a PUT request that says that request is - * complete. In this case, the server can begin sending the response. The - * 0x03 is a GET request that signals that the request is not finished. When - * the server receives a 0x83, the client is signaling the server that it is - * done with its request. - * - * TODO: Extend the ClientOperation and reuse the methods defined - * TODO: in that class. - * + * <STRONG>Request Codes</STRONG> There are four different request codes that + * are in this class. 0x02 is a PUT request that signals that the request is not + * complete and requires an additional OBEX packet. 0x82 is a PUT request that + * says that request is complete. In this case, the server can begin sending the + * response. The 0x03 is a GET request that signals that the request is not + * finished. When the server receives a 0x83, the client is signaling the server + * that it is done with its request. TODO: Extend the ClientOperation and reuse + * the methods defined TODO: in that class. * @hide */ public final class ServerOperation implements Operation, BaseStream { @@ -94,19 +90,12 @@ public final class ServerOperation implements Operation, BaseStream { /** * Creates new ServerOperation - * * @param p the parent that created this object - * * @param in the input stream to read from - * * @param out the output stream to write to - * * @param request the initial request that was received from the client - * * @param maxSize the max packet size that the client will accept - * * @param listen the listener that is responding to the request - * * @throws IOException if an IO error occurs */ public ServerOperation(ServerSession p, InputStream in, int request, int maxSize, @@ -240,17 +229,16 @@ public final class ServerOperation implements Operation, BaseStream { } /** - * Determines if the operation should continue or should wait. If it - * should continue, this method will continue the operation. - * + * Determines if the operation should continue or should wait. If it should + * continue, this method will continue the operation. * @param sendEmpty if <code>true</code> then this will continue the - * operation even if no headers will be sent; if <code>false</code> then - * this method will only continue the operation if there are headers to - * send - * @param isStream if<code>true</code> the stream is input stream, otherwise - * output stream + * operation even if no headers will be sent; if <code>false</code> + * then this method will only continue the operation if there are + * headers to send + * @param inStream if<code>true</code> the stream is input stream, otherwise + * output stream * @return <code>true</code> if the operation was completed; - * <code>false</code> if no operation took place + * <code>false</code> if no operation took place */ public synchronized boolean continueOperation(boolean sendEmpty, boolean inStream) throws IOException { @@ -277,15 +265,13 @@ public final class ServerOperation implements Operation, BaseStream { } /** - * Sends a reply to the client. If the reply is a OBEX_HTTP_CONTINUE, it + * Sends a reply to the client. If the reply is a OBEX_HTTP_CONTINUE, it * will wait for a response from the client before ending. - * * @param type the response code to send back to the client - * * @return <code>true</code> if the final bit was not set on the reply; - * <code>false</code> if no reply was received because the operation ended, - * an abort was received, or the final bit was set in the reply - * + * <code>false</code> if no reply was received because the operation + * ended, an abort was received, or the final bit was set in the + * reply * @throws IOException if an IO error occurs */ public synchronized boolean sendReply(int type) throws IOException { @@ -492,12 +478,11 @@ public final class ServerOperation implements Operation, BaseStream { } /** - * Sends an ABORT message to the server. By calling this method, the + * Sends an ABORT message to the server. By calling this method, the * corresponding input and output streams will be closed along with this * object. - * - * @throws IOException if the transaction has already ended or if an - * OBEX server called this method + * @throws IOException if the transaction has already ended or if an OBEX + * server called this method */ public void abort() throws IOException { throw new IOException("Called from a server"); @@ -505,11 +490,9 @@ public final class ServerOperation implements Operation, BaseStream { /** * Returns the headers that have been received during the operation. - * Modifying the object returned has no effect on the headers that are - * sent or retrieved. - * + * Modifying the object returned has no effect on the headers that are sent + * or retrieved. * @return the headers received during this <code>Operation</code> - * * @throws IOException if this <code>Operation</code> has been closed */ public HeaderSet getReceivedHeader() throws IOException { @@ -520,14 +503,11 @@ public final class ServerOperation implements Operation, BaseStream { /** * Specifies the headers that should be sent in the next OBEX message that * is sent. - * * @param headers the headers to send in the next message - * - * @throws IOException if this <code>Operation</code> has been closed - * or the transaction has ended and no further messages will be exchanged - * + * @throws IOException if this <code>Operation</code> has been closed or the + * transaction has ended and no further messages will be exchanged * @throws IllegalArgumentException if <code>headers</code> was not created - * by a call to <code>ServerRequestHandler.createHeaderSet()</code> + * by a call to <code>ServerRequestHandler.createHeaderSet()</code> */ public void sendHeaders(HeaderSet headers) throws IOException { ensureOpen(); @@ -546,15 +526,14 @@ public final class ServerOperation implements Operation, BaseStream { } /** - * Retrieves the response code retrieved from the server. Response codes - * are defined in the <code>ResponseCodes</code> interface. - * + * Retrieves the response code retrieved from the server. Response codes are + * defined in the <code>ResponseCodes</code> interface. * @return the response code retrieved from the server - * * @throws IOException if an error occurred in the transport layer during - * the transaction; if this method is called on a <code>HeaderSet</code> - * object created by calling <code>createHeaderSet</code> in a - * <code>ClientSession</code> object; if this is called from a server + * the transaction; if this method is called on a + * <code>HeaderSet</code> object created by calling + * <code>createHeaderSet</code> in a <code>ClientSession</code> + * object; if this is called from a server */ public int getResponseCode() throws IOException { throw new IOException("Called from a server"); @@ -562,7 +541,6 @@ public final class ServerOperation implements Operation, BaseStream { /** * Always returns <code>null</code> - * * @return <code>null</code> */ public String getEncoding() { @@ -573,9 +551,8 @@ public final class ServerOperation implements Operation, BaseStream { * Returns the type of content that the resource connected to is providing. * E.g. if the connection is via HTTP, then the value of the content-type * header field is returned. - * * @return the content type of the resource that the URL references, or - * <code>null</code> if not known + * <code>null</code> if not known */ public String getType() { try { @@ -587,11 +564,10 @@ public final class ServerOperation implements Operation, BaseStream { /** * Returns the length of the content which is being provided. E.g. if the - * connection is via HTTP, then the value of the content-length header - * field is returned. - * + * connection is via HTTP, then the value of the content-length header field + * is returned. * @return the content length of the resource that this connection's URL - * references, or -1 if the content length is not known + * references, or -1 if the content length is not known */ public long getLength() { try { @@ -613,9 +589,7 @@ public final class ServerOperation implements Operation, BaseStream { /** * Open and return an input stream for a connection. - * * @return an input stream - * * @throws IOException if an I/O error occurs */ public InputStream openInputStream() throws IOException { @@ -625,9 +599,7 @@ public final class ServerOperation implements Operation, BaseStream { /** * Open and return a data input stream for a connection. - * * @return an input stream - * * @throws IOException if an I/O error occurs */ public DataInputStream openDataInputStream() throws IOException { @@ -636,9 +608,7 @@ public final class ServerOperation implements Operation, BaseStream { /** * Open and return an output stream for a connection. - * * @return an output stream - * * @throws IOException if an I/O error occurs */ public OutputStream openOutputStream() throws IOException { @@ -661,9 +631,7 @@ public final class ServerOperation implements Operation, BaseStream { /** * Open and return a data output stream for a connection. - * * @return an output stream - * * @throws IOException if an I/O error occurs */ public DataOutputStream openDataOutputStream() throws IOException { @@ -672,7 +640,6 @@ public final class ServerOperation implements Operation, BaseStream { /** * Closes the connection and ends the transaction - * * @throws IOException if the operation has already ended or is closed */ public void close() throws IOException { @@ -682,7 +649,6 @@ public final class ServerOperation implements Operation, BaseStream { /** * Verifies that the connection is open and no exceptions should be thrown. - * * @throws IOException if an exception needs to be thrown */ public void ensureOpen() throws IOException { @@ -695,26 +661,23 @@ public final class ServerOperation implements Operation, BaseStream { } /** - * Verifies that additional information may be sent. In other words, the + * Verifies that additional information may be sent. In other words, the * operation is not done. * <P> - * Included to implement the BaseStream interface only. It does not do + * Included to implement the BaseStream interface only. It does not do * anything on the server side since the operation of the Operation object * is not done until after the handler returns from its method. - * * @throws IOException if the operation is completed */ public void ensureNotDone() throws IOException { } /** - * Called when the output or input stream is closed. It does not do - * anything on the server side since the operation of the Operation object - * is not done until after the handler returns from its method. - * + * Called when the output or input stream is closed. It does not do anything + * on the server side since the operation of the Operation object is not + * done until after the handler returns from its method. * @param inStream <code>true</code> if the input stream is closed; - * <code>false</code> if the output stream is closed - * + * <code>false</code> if the output stream is closed * @throws IOException if an IO error occurs */ public void streamClosed(boolean inStream) throws IOException { diff --git a/obex/javax/obex/ServerRequestHandler.java b/obex/javax/obex/ServerRequestHandler.java index e468b83..d93e5b6 100644 --- a/obex/javax/obex/ServerRequestHandler.java +++ b/obex/javax/obex/ServerRequestHandler.java @@ -33,40 +33,38 @@ package javax.obex; /** - * The <code>ServerRequestHandler</code> class defines an event - * listener that will respond to OBEX requests made to the server. + * The <code>ServerRequestHandler</code> class defines an event listener that + * will respond to OBEX requests made to the server. * <P> - * The <code>onConnect()</code>, <code>onSetPath()</code>, <code>onDelete()</code>, - * <code>onGet()</code>, - * and <code>onPut()</code> methods may return any response code defined - * in the <code>ResponseCodes</code> class except for - * <code>OBEX_HTTP_CONTINUE</code>. If <code>OBEX_HTTP_CONTINUE</code> or - * a value not defined in the <code>ResponseCodes</code> class is returned, - * the server implementation will send an <code>OBEX_HTTP_INTERNAL_ERROR</code> - * response to the client. + * The <code>onConnect()</code>, <code>onSetPath()</code>, + * <code>onDelete()</code>, <code>onGet()</code>, and <code>onPut()</code> + * methods may return any response code defined in the + * <code>ResponseCodes</code> class except for <code>OBEX_HTTP_CONTINUE</code>. + * If <code>OBEX_HTTP_CONTINUE</code> or a value not defined in the + * <code>ResponseCodes</code> class is returned, the server implementation will + * send an <code>OBEX_HTTP_INTERNAL_ERROR</code> response to the client. * <P> * <STRONG>Connection ID and Target Headers</STRONG> * <P> * According to the IrOBEX specification, a packet may not contain a Connection - * ID and Target header. Since the Connection ID header is managed by the + * ID and Target header. Since the Connection ID header is managed by the * implementation, it will not send a Connection ID header, if a Connection ID - * was specified, in a packet that has a Target header. In other words, if an - * application adds a Target header to a <code>HeaderSet</code> object used - * in an OBEX operation and a Connection ID was specified, no Connection ID - * will be sent in the packet containing the Target header. + * was specified, in a packet that has a Target header. In other words, if an + * application adds a Target header to a <code>HeaderSet</code> object used in + * an OBEX operation and a Connection ID was specified, no Connection ID will be + * sent in the packet containing the Target header. * <P> * <STRONG>CREATE-EMPTY Requests</STRONG> * <P> * A CREATE-EMPTY request allows clients to create empty objects on the server. - * When a CREATE-EMPTY request is received, the <code>onPut()</code> method - * will be called by the implementation. To differentiate between a normal - * PUT request and a CREATE-EMPTY request, an application must open the - * <code>InputStream</code> from the <code>Operation</code> object passed - * to the <code>onPut()</code> method. For a PUT request, the application - * will be able to read Body data from this <code>InputStream</code>. For - * a CREATE-EMPTY request, there will be no Body data to read. Therefore, - * a call to <code>InputStream.read()</code> will return -1. - * + * When a CREATE-EMPTY request is received, the <code>onPut()</code> method will + * be called by the implementation. To differentiate between a normal PUT + * request and a CREATE-EMPTY request, an application must open the + * <code>InputStream</code> from the <code>Operation</code> object passed to the + * <code>onPut()</code> method. For a PUT request, the application will be able + * to read Body data from this <code>InputStream</code>. For a CREATE-EMPTY + * request, there will be no Body data to read. Therefore, a call to + * <code>InputStream.read()</code> will return -1. * @hide */ public class ServerRequestHandler { @@ -74,8 +72,8 @@ public class ServerRequestHandler { private long mConnectionId; /** - * Creates a <code>ServerRequestHandler</code>. - */ + * Creates a <code>ServerRequestHandler</code>. + */ protected ServerRequestHandler() { /* * A connection ID of -1 implies there is no conenction ID @@ -85,12 +83,10 @@ public class ServerRequestHandler { /** * Sets the connection ID header to include in the reply packets. - * - * @param connectionId the connection ID to use; -1 if no connection ID should be - * sent - * - * @throws IllegalArgumentException if <code>id</code> is not in the - * range -1 to 2<sup>32</sup>-1 + * @param connectionId the connection ID to use; -1 if no connection ID + * should be sent + * @throws IllegalArgumentException if <code>id</code> is not in the range + * -1 to 2<sup>32</sup>-1 */ public void setConnectionId(final long connectionId) { if ((connectionId < -1) || (connectionId > 0xFFFFFFFFL)) { @@ -102,9 +98,8 @@ public class ServerRequestHandler { /** * Retrieves the connection ID that is being used in the present connection. * This method will return -1 if no connection ID is being used. - * * @return the connection id being used or -1 if no connection ID is being - * used + * used */ public long getConnectionId() { return mConnectionId; @@ -113,23 +108,21 @@ public class ServerRequestHandler { /** * Called when a CONNECT request is received. * <P> - * If this method is not implemented by the class that extends this - * class, <code>onConnect()</code> will always return an - * <code>OBEX_HTTP_OK</code> response code. + * If this method is not implemented by the class that extends this class, + * <code>onConnect()</code> will always return an <code>OBEX_HTTP_OK</code> + * response code. * <P> * The headers received in the request can be retrieved from the - * <code>request</code> argument. The headers that should be sent - * in the reply must be specified in the <code>reply</code> argument. - * + * <code>request</code> argument. The headers that should be sent in the + * reply must be specified in the <code>reply</code> argument. * @param request contains the headers sent by the client; - * <code>request</code> will never be <code>null</code> - * + * <code>request</code> will never be <code>null</code> * @param reply the headers that should be sent in the reply; - * <code>reply</code> will never be <code>null</code> - * - * @return a response code defined in <code>ResponseCodes</code> that will be - * returned to the client; if an invalid response code is provided, the - * <code>OBEX_HTTP_INTERNAL_ERROR</code> response code will be used + * <code>reply</code> will never be <code>null</code> + * @return a response code defined in <code>ResponseCodes</code> that will + * be returned to the client; if an invalid response code is + * provided, the <code>OBEX_HTTP_INTERNAL_ERROR</code> response code + * will be used */ public int onConnect(HeaderSet request, HeaderSet reply) { return ResponseCodes.OBEX_HTTP_OK; @@ -139,14 +132,12 @@ public class ServerRequestHandler { * Called when a DISCONNECT request is received. * <P> * The headers received in the request can be retrieved from the - * <code>request</code> argument. The headers that should be sent - * in the reply must be specified in the <code>reply</code> argument. - * + * <code>request</code> argument. The headers that should be sent in the + * reply must be specified in the <code>reply</code> argument. * @param request contains the headers sent by the client; - * <code>request</code> will never be <code>null</code> - * + * <code>request</code> will never be <code>null</code> * @param reply the headers that should be sent in the reply; - * <code>reply</code> will never be <code>null</code> + * <code>reply</code> will never be <code>null</code> */ public void onDisconnect(HeaderSet request, HeaderSet reply) { } @@ -154,32 +145,28 @@ public class ServerRequestHandler { /** * Called when a SETPATH request is received. * <P> - * If this method is not implemented by the class that extends this - * class, <code>onSetPath()</code> will always return an + * If this method is not implemented by the class that extends this class, + * <code>onSetPath()</code> will always return an * <code>OBEX_HTTP_NOT_IMPLEMENTED</code> response code. * <P> * The headers received in the request can be retrieved from the - * <code>request</code> argument. The headers that should be sent - * in the reply must be specified in the <code>reply</code> argument. - * + * <code>request</code> argument. The headers that should be sent in the + * reply must be specified in the <code>reply</code> argument. * @param request contains the headers sent by the client; - * <code>request</code> will never be <code>null</code> - * + * <code>request</code> will never be <code>null</code> * @param reply the headers that should be sent in the reply; - * <code>reply</code> will never be <code>null</code> - * + * <code>reply</code> will never be <code>null</code> * @param backup <code>true</code> if the client requests that the server - * back up one directory before changing to the path described by - * <code>name</code>; <code>false</code> to apply the request to the present - * path - * + * back up one directory before changing to the path described by + * <code>name</code>; <code>false</code> to apply the request to the + * present path * @param create <code>true</code> if the path should be created if it does - * not already exist; <code>false</code> if the path should not be created - * if it does not exist and an error code should be returned - * - * @return a response code defined in <code>ResponseCodes</code> that will be - * returned to the client; if an invalid response code is provided, the - * <code>OBEX_HTTP_INTERNAL_ERROR</code> response code will be used + * not already exist; <code>false</code> if the path should not be + * created if it does not exist and an error code should be returned + * @return a response code defined in <code>ResponseCodes</code> that will + * be returned to the client; if an invalid response code is + * provided, the <code>OBEX_HTTP_INTERNAL_ERROR</code> response code + * will be used */ public int onSetPath(HeaderSet request, HeaderSet reply, boolean backup, boolean create) { @@ -189,23 +176,21 @@ public class ServerRequestHandler { /** * Called when a DELETE request is received. * <P> - * If this method is not implemented by the class that extends this - * class, <code>onDelete()</code> will always return an + * If this method is not implemented by the class that extends this class, + * <code>onDelete()</code> will always return an * <code>OBEX_HTTP_NOT_IMPLEMENTED</code> response code. * <P> * The headers received in the request can be retrieved from the - * <code>request</code> argument. The headers that should be sent - * in the reply must be specified in the <code>reply</code> argument. - * + * <code>request</code> argument. The headers that should be sent in the + * reply must be specified in the <code>reply</code> argument. * @param request contains the headers sent by the client; - * <code>request</code> will never be <code>null</code> - * + * <code>request</code> will never be <code>null</code> * @param reply the headers that should be sent in the reply; - * <code>reply</code> will never be <code>null</code> - * - * @return a response code defined in <code>ResponseCodes</code> that will be - * returned to the client; if an invalid response code is provided, the - * <code>OBEX_HTTP_INTERNAL_ERROR</code> response code will be used + * <code>reply</code> will never be <code>null</code> + * @return a response code defined in <code>ResponseCodes</code> that will + * be returned to the client; if an invalid response code is + * provided, the <code>OBEX_HTTP_INTERNAL_ERROR</code> response code + * will be used */ public int onDelete(HeaderSet request, HeaderSet reply) { return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED; @@ -214,20 +199,19 @@ public class ServerRequestHandler { /** * Called when a PUT request is received. * <P> - * If this method is not implemented by the class that extends this - * class, <code>onPut()</code> will always return an + * If this method is not implemented by the class that extends this class, + * <code>onPut()</code> will always return an * <code>OBEX_HTTP_NOT_IMPLEMENTED</code> response code. * <P> * If an ABORT request is received during the processing of a PUT request, * <code>op</code> will be closed by the implementation. - * * @param operation contains the headers sent by the client and allows new - * headers to be sent in the reply; <code>op</code> will never be - * <code>null</code> - * - * @return a response code defined in <code>ResponseCodes</code> that will be - * returned to the client; if an invalid response code is provided, the - * <code>OBEX_HTTP_INTERNAL_ERROR</code> response code will be used + * headers to be sent in the reply; <code>op</code> will never be + * <code>null</code> + * @return a response code defined in <code>ResponseCodes</code> that will + * be returned to the client; if an invalid response code is + * provided, the <code>OBEX_HTTP_INTERNAL_ERROR</code> response code + * will be used */ public int onPut(Operation operation) { return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED; @@ -236,20 +220,19 @@ public class ServerRequestHandler { /** * Called when a GET request is received. * <P> - * If this method is not implemented by the class that extends this - * class, <code>onGet()</code> will always return an + * If this method is not implemented by the class that extends this class, + * <code>onGet()</code> will always return an * <code>OBEX_HTTP_NOT_IMPLEMENTED</code> response code. * <P> * If an ABORT request is received during the processing of a GET request, * <code>op</code> will be closed by the implementation. - * * @param operation contains the headers sent by the client and allows new - * headers to be sent in the reply; <code>op</code> will never be - * <code>null</code> - * - * @return a response code defined in <code>ResponseCodes</code> that will be - * returned to the client; if an invalid response code is provided, the - * <code>OBEX_HTTP_INTERNAL_ERROR</code> response code will be used + * headers to be sent in the reply; <code>op</code> will never be + * <code>null</code> + * @return a response code defined in <code>ResponseCodes</code> that will + * be returned to the client; if an invalid response code is + * provided, the <code>OBEX_HTTP_INTERNAL_ERROR</code> response code + * will be used */ public int onGet(Operation operation) { return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED; @@ -262,9 +245,8 @@ public class ServerRequestHandler { * <P> * If this method is not implemented by the class that extends this class, * this method will do nothing. - * * @param userName the user name returned in the authentication response; - * <code>null</code> if no user name was provided in the response + * <code>null</code> if no user name was provided in the response */ public void onAuthenticationFailure(byte[] userName) { } @@ -274,7 +256,6 @@ public class ServerRequestHandler { * <P> * If this method is not implemented by the class that extends this class, * this method will do nothing. - * */ public void updateStatus(String message) { } @@ -284,7 +265,6 @@ public class ServerRequestHandler { * <P> * If this method is not implemented by the class that extends this class, * this method will do nothing. - * */ public void onClose() { } diff --git a/obex/javax/obex/ServerSession.java b/obex/javax/obex/ServerSession.java index 3a0e8150..423d5a7 100644 --- a/obex/javax/obex/ServerSession.java +++ b/obex/javax/obex/ServerSession.java @@ -40,7 +40,6 @@ import java.io.OutputStream; /** * This class in an implementation of the OBEX ServerSession. - * * @hide */ public final class ServerSession extends ObexSession implements Runnable { @@ -63,19 +62,11 @@ public final class ServerSession extends ObexSession implements Runnable { /** * Creates new ServerSession. - * - * @param trans - * the connection to the client - * - * @param handler - * the event listener that will process requests - * - * @param auth - * the authenticator to use with this connection - * - * @throws IOException - * if an error occurred while opening the input and output - * streams + * @param trans the connection to the client + * @param handler the event listener that will process requests + * @param auth the authenticator to use with this connection + * @throws IOException if an error occurred while opening the input and + * output streams */ public ServerSession(ObexTransport trans, ServerRequestHandler handler, Authenticator auth) throws IOException { @@ -163,12 +154,8 @@ public final class ServerSession extends ObexSession implements Runnable { * <code>ServerOperation</code> object will always reply with a * OBEX_HTTP_CONTINUE reply. It will only reply if further information is * needed. - * - * @param type - * the type of request received; either 0x02 or 0x82 - * - * @throws IOException - * if an error occurred at the transport layer + * @param type the type of request received; either 0x02 or 0x82 + * @throws IOException if an error occurred at the transport layer */ private void handlePutRequest(int type) throws IOException { ServerOperation op = new ServerOperation(this, mInput, type, mMaxPacketLength, mListener); @@ -191,7 +178,14 @@ public final class ServerSession extends ObexSession implements Runnable { op.sendReply(response); } } catch (Exception e) { - sendResponse(ResponseCodes.OBEX_HTTP_INTERNAL_ERROR, null); + /*To fix bugs in aborted cases, + *(client abort file transfer prior to the last packet which has the end of body header, + *internal error should not be sent because server has already replied with + *OK response in "sendReply") + */ + if (!op.isAborted) { + sendResponse(ResponseCodes.OBEX_HTTP_INTERNAL_ERROR, null); + } } } @@ -205,12 +199,8 @@ public final class ServerSession extends ObexSession implements Runnable { * <code>ServerOperation</code> object will always reply with a * OBEX_HTTP_CONTINUE reply. It will only reply if further information is * needed. - * - * @param type - * the type of request received; either 0x03 or 0x83 - * - * @throws IOException - * if an error occurred at the transport layer + * @param type the type of request received; either 0x03 or 0x83 + * @throws IOException if an error occurred at the transport layer */ private void handleGetRequest(int type) throws IOException { ServerOperation op = new ServerOperation(this, mInput, type, mMaxPacketLength, mListener); @@ -227,15 +217,9 @@ public final class ServerSession extends ObexSession implements Runnable { /** * Send standard response. - * - * @param code - * the response code to send - * - * @param header - * the headers to include in the response - * - * @throws IOException - * if an IO error occurs + * @param code the response code to send + * @param header the headers to include in the response + * @throws IOException if an IO error occurs */ public void sendResponse(int code, byte[] header) throws IOException { int totalLength = 3; @@ -265,9 +249,7 @@ public final class ServerSession extends ObexSession implements Runnable { * <code>ServerRequestHandler</code> object. After the handler processes the * request, this method will create a reply message to send to the server * with the response code provided. - * - * @throws IOException - * if an error occurred at the transport layer + * @throws IOException if an error occurred at the transport layer */ private void handleSetPathRequest() throws IOException { int length; @@ -393,9 +375,7 @@ public final class ServerSession extends ObexSession implements Runnable { * will create a <code>HeaderSet</code> object to pass to the * <code>ServerRequestHandler</code> object. After the handler processes the * request, this method will create a reply message to send to the server. - * - * @throws IOException - * if an error occurred at the transport layer + * @throws IOException if an error occurred at the transport layer */ private void handleDisconnectRequest() throws IOException { int length; @@ -500,9 +480,7 @@ public final class ServerSession extends ObexSession implements Runnable { * <code>ServerRequestHandler</code> object. After the handler processes the * request, this method will create a reply message to send to the server * with the response code provided. - * - * @throws IOException - * if an error occurred at the transport layer + * @throws IOException if an error occurred at the transport layer */ private void handleConnectRequest() throws IOException { int packetLength; @@ -660,10 +638,7 @@ public final class ServerSession extends ObexSession implements Runnable { /** * Verifies that the response code is valid. If it is not valid, it will * return the <code>OBEX_HTTP_INTERNAL_ERROR</code> response code. - * - * @param code - * the response code to check - * + * @param code the response code to check * @return the valid response code or <code>OBEX_HTTP_INTERNAL_ERROR</code> * if <code>code</code> is not valid */ diff --git a/obex/javax/obex/SessionNotifier.java b/obex/javax/obex/SessionNotifier.java index 36e0ebf..9836dd6 100644 --- a/obex/javax/obex/SessionNotifier.java +++ b/obex/javax/obex/SessionNotifier.java @@ -36,73 +36,53 @@ import java.io.IOException; /** * The <code>SessionNotifier</code> interface defines a connection notifier for - * server-side OBEX connections. When a <code>SessionNotifier</code> is - * created and calls <code>acceptAndOpen()</code>, it will begin listening for - * clients to create a connection at the transport layer. When the transport - * layer connection is received, the <code>acceptAndOpen()</code> method will - * return a <code>javax.microedition.io.Connection</code> that is the - * connection to the client. The <code>acceptAndOpen()</code> method also takes a + * server-side OBEX connections. When a <code>SessionNotifier</code> is created + * and calls <code>acceptAndOpen()</code>, it will begin listening for clients + * to create a connection at the transport layer. When the transport layer + * connection is received, the <code>acceptAndOpen()</code> method will return a + * <code>javax.microedition.io.Connection</code> that is the connection to the + * client. The <code>acceptAndOpen()</code> method also takes a * <code>ServerRequestHandler</code> argument that will process the requests * from the client that connects to the server. - * * @hide */ public interface SessionNotifier { /** * Waits for a transport layer connection to be established and specifies - * the handler to handle the requests from the client. No authenticator - * is associated with this connection, therefore, it is implementation + * the handler to handle the requests from the client. No authenticator is + * associated with this connection, therefore, it is implementation * dependent as to how an authentication challenge and authentication * response header will be received and processed. * <P> - * <H4>Additional Note for OBEX over Bluetooth</H4> - * If this method is called on a <code>SessionNotifier</code> object that - * does not have a <code>ServiceRecord</code> in the SDDB, the - * <code>ServiceRecord</code> for this object will be added to the SDDB. - * This method requests the BCC to put the - * local device in connectible mode so that it will respond to + * <H4>Additional Note for OBEX over Bluetooth</H4> If this method is called + * on a <code>SessionNotifier</code> object that does not have a + * <code>ServiceRecord</code> in the SDDB, the <code>ServiceRecord</code> + * for this object will be added to the SDDB. This method requests the BCC + * to put the local device in connectable mode so that it will respond to * connection attempts by clients. * <P> - * The following checks are done to verify that the service record - * provided is valid. If any of these checks fail, then a + * The following checks are done to verify that the service record provided + * is valid. If any of these checks fail, then a * <code>ServiceRegistrationException</code> is thrown. * <UL> - * <LI>ServiceClassIDList and ProtocolDescriptorList, the mandatory - * service attributes for a <code>btgoep</code> service record, must be - * present in the <code>ServiceRecord</code> associated with this notifier. + * <LI>ServiceClassIDList and ProtocolDescriptorList, the mandatory service + * attributes for a <code>btgoep</code> service record, must be present in + * the <code>ServiceRecord</code> associated with this notifier. * <LI>L2CAP, RFCOMM and OBEX must all be in the ProtocolDescriptorList - * <LI>The <code>ServiceRecord</code> associated with this notifier must - * not have changed the RFCOMM server channel number + * <LI>The <code>ServiceRecord</code> associated with this notifier must not + * have changed the RFCOMM server channel number * </UL> * <P> * This method will not ensure that <code>ServiceRecord</code> associated - * with this notifier is a completely - * valid service record. It is the responsibility of the application to - * ensure that the service record follows all of the applicable - * syntactic and semantic rules for service record correctness. - * + * with this notifier is a completely valid service record. It is the + * responsibility of the application to ensure that the service record + * follows all of the applicable syntactic and semantic rules for service + * record correctness. * @param handler the request handler that will respond to OBEX requests - * * @return the connection to the client - * * @throws IOException if an error occurs in the transport layer - * - * @throws NullPointerException if <code>handler</code> is - * <code>null</code> - * - * @throws ServiceRegistrationException if the structure of the - * associated service record is invalid or if the service record - * could not be added successfully to the local SDDB. The - * structure of service record is invalid if the service - * record is missing any mandatory service attributes, or has - * changed any of the values described above which are fixed and - * cannot be changed. Failures to add the record to the SDDB could - * be due to insufficient disk space, database locks, etc. - * - * @throws BluetoothStateException if the server device could - * not be placed in connectible mode because the device user has - * configured the device to be non-connectible + * @throws NullPointerException if <code>handler</code> is <code>null</code> */ ObexSession acceptAndOpen(ServerRequestHandler handler) throws IOException; @@ -112,56 +92,37 @@ public interface SessionNotifier { * <code>Authenticator</code> to use to respond to authentication challenge * and authentication response headers. * <P> - * <H4>Additional Note for OBEX over Bluetooth</H4> - * If this method is called on a <code>SessionNotifier</code> object that - * does not have a <code>ServiceRecord</code> in the SDDB, the - * <code>ServiceRecord</code> for this object will be added to the SDDB. - * This method requests the BCC to put the - * local device in connectible mode so that it will respond to + * <H4>Additional Note for OBEX over Bluetooth</H4> If this method is called + * on a <code>SessionNotifier</code> object that does not have a + * <code>ServiceRecord</code> in the SDDB, the <code>ServiceRecord</code> + * for this object will be added to the SDDB. This method requests the BCC + * to put the local device in connectable mode so that it will respond to * connection attempts by clients. * <P> - * The following checks are done to verify that the service record - * provided is valid. If any of these checks fail, then a + * The following checks are done to verify that the service record provided + * is valid. If any of these checks fail, then a * <code>ServiceRegistrationException</code> is thrown. * <UL> - * <LI>ServiceClassIDList and ProtocolDescriptorList, the mandatory - * service attributes for a <code>btgoep</code> service record, must be - * present in the <code>ServiceRecord</code> associated with this notifier. + * <LI>ServiceClassIDList and ProtocolDescriptorList, the mandatory service + * attributes for a <code>btgoep</code> service record, must be present in + * the <code>ServiceRecord</code> associated with this notifier. * <LI>L2CAP, RFCOMM and OBEX must all be in the ProtocolDescriptorList - * <LI>The <code>ServiceRecord</code> associated with this notifier must - * not have changed the RFCOMM server channel number + * <LI>The <code>ServiceRecord</code> associated with this notifier must not + * have changed the RFCOMM server channel number * </UL> * <P> * This method will not ensure that <code>ServiceRecord</code> associated - * with this notifier is a completely - * valid service record. It is the responsibility of the application to - * ensure that the service record follows all of the applicable - * syntactic and semantic rules for service record correctness. - * + * with this notifier is a completely valid service record. It is the + * responsibility of the application to ensure that the service record + * follows all of the applicable syntactic and semantic rules for service + * record correctness. * @param handler the request handler that will respond to OBEX requests - * * @param auth the <code>Authenticator</code> to use with this connection; - * if <code>null</code> then no <code>Authenticator</code> will be used - * + * if <code>null</code> then no <code>Authenticator</code> will be + * used * @return the connection to the client - * * @throws IOException if an error occurs in the transport layer - * - * @throws NullPointerException if <code>handler</code> is - * <code>null</code> - * - * @throws ServiceRegistrationException if the structure of the - * associated service record is invalid or if the service record - * could not be added successfully to the local SDDB. The - * structure of service record is invalid if the service - * record is missing any mandatory service attributes, or has - * changed any of the values described above which are fixed and - * cannot be changed. Failures to add the record to the SDDB could - * be due to insufficient disk space, database locks, etc. - * - * @throws BluetoothStateException if the server device could - * not be placed in connectible mode because the device user has - * configured the device to be non-connectible + * @throws NullPointerException if <code>handler</code> is <code>null</code> */ ObexSession acceptAndOpen(ServerRequestHandler handler, Authenticator auth) throws IOException; } |