public final class ServerOperation extends Object implements Operation, BaseStream
Request Codes 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.
Modifier and Type | Field and Description |
---|---|
boolean |
finalBitSet |
boolean |
isAborted |
HeaderSet |
replyHeader |
HeaderSet |
requestHeader |
Constructor and Description |
---|
ServerOperation(ServerSession p,
InputStream in,
int request,
int maxSize,
ServerRequestHandler listen)
Creates new ServerOperation
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Sends an ABORT message to the server.
|
void |
close()
Closes the connection and ends the transaction
|
boolean |
continueOperation(boolean sendEmpty,
boolean inStream)
Determines if the operation should continue or should wait.
|
void |
ensureNotDone()
Verifies that additional information may be sent.
|
void |
ensureOpen()
Verifies that the connection is open and no exceptions should be thrown.
|
String |
getEncoding()
Always returns
null |
int |
getHeaderLength() |
long |
getLength()
Returns the length of the content which is being provided.
|
int |
getMaxPacketSize() |
HeaderSet |
getReceivedHeader()
Returns the headers that have been received during the operation.
|
int |
getResponseCode()
Retrieves the response code retrieved from the server.
|
String |
getType()
Returns the type of content that the resource connected to is providing.
|
boolean |
isValidBody() |
void |
noBodyHeader() |
DataInputStream |
openDataInputStream()
Open and return a data input stream for a connection.
|
DataOutputStream |
openDataOutputStream()
Open and return a data output stream for a connection.
|
InputStream |
openInputStream()
Open and return an input stream for a connection.
|
OutputStream |
openOutputStream()
Open and return an output stream for a connection.
|
void |
sendHeaders(HeaderSet headers)
Specifies the headers that should be sent in the next OBEX message that
is sent.
|
boolean |
sendReply(int type)
Sends a reply to the client.
|
void |
streamClosed(boolean inStream)
Called when the output or input stream is closed.
|
public boolean isAborted
public HeaderSet requestHeader
public HeaderSet replyHeader
public boolean finalBitSet
public ServerOperation(ServerSession p, InputStream in, int request, int maxSize, ServerRequestHandler listen) throws IOException
p
- the parent that created this objectin
- the input stream to read fromout
- the output stream to write torequest
- the initial request that was received from the clientmaxSize
- the max packet size that the client will acceptlisten
- the listener that is responding to the requestIOException
- if an IO error occurspublic boolean isValidBody()
public boolean continueOperation(boolean sendEmpty, boolean inStream) throws IOException
continueOperation
in interface BaseStream
sendEmpty
- if true
then this will continue the
operation even if no headers will be sent; if false
then this method will only continue the operation if there are
headers to sendinStream
- iftrue
the stream is input stream, otherwise
output streamtrue
if the operation was completed;
false
if no operation took placeIOException
- if an IO error occurspublic boolean sendReply(int type) throws IOException
type
- the response code to send back to the clienttrue
if the final bit was not set on the reply;
false
if no reply was received because the operation
ended, an abort was received, the final bit was set in the
reply or SRM is active.IOException
- if an IO error occurspublic void abort() throws IOException
abort
in interface Operation
IOException
- if the transaction has already ended or if an OBEX
server called this methodpublic HeaderSet getReceivedHeader() throws IOException
getReceivedHeader
in interface Operation
Operation
IOException
- if this Operation
has been closedpublic void sendHeaders(HeaderSet headers) throws IOException
sendHeaders
in interface Operation
headers
- the headers to send in the next messageIOException
- if this Operation
has been closed or the
transaction has ended and no further messages will be exchangedIllegalArgumentException
- if headers
was not created
by a call to ServerRequestHandler.createHeaderSet()
public int getResponseCode() throws IOException
ResponseCodes
interface.getResponseCode
in interface Operation
IOException
- if an error occurred in the transport layer during
the transaction; if this method is called on a
HeaderSet
object created by calling
createHeaderSet
in a ClientSession
object; if this is called from a serverResponseCodes
public String getEncoding()
null
getEncoding
in interface Operation
null
public String getType()
public long getLength()
public int getMaxPacketSize()
getMaxPacketSize
in interface Operation
public int getHeaderLength()
getHeaderLength
in interface Operation
public InputStream openInputStream() throws IOException
openInputStream
in interface Operation
IOException
- if an I/O error occurspublic DataInputStream openDataInputStream() throws IOException
openDataInputStream
in interface Operation
IOException
- if an I/O error occurspublic OutputStream openOutputStream() throws IOException
openOutputStream
in interface Operation
IOException
- if an I/O error occurspublic DataOutputStream openDataOutputStream() throws IOException
openDataOutputStream
in interface Operation
IOException
- if an I/O error occurspublic void close() throws IOException
close
in interface Operation
IOException
- if the operation has already ended or is closedpublic void ensureOpen() throws IOException
ensureOpen
in interface BaseStream
IOException
- if an exception needs to be thrownpublic void ensureNotDone() throws IOException
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.
ensureNotDone
in interface BaseStream
IOException
- if the operation is completedpublic void streamClosed(boolean inStream) throws IOException
streamClosed
in interface BaseStream
inStream
- true
if the input stream is closed;
false
if the output stream is closedIOException
- if an IO error occurspublic void noBodyHeader()
noBodyHeader
in interface Operation