|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.acplt.oncrpc.XdrEncodingStream org.acplt.oncrpc.XdrTcpEncodingStream
public class XdrTcpEncodingStream
The XdrTcpEncodingStream
class provides the necessary
functionality to XdrEncodingStream
to send XDR records to the
network using the stream-oriented TCP/IP.
Field Summary | |
---|---|
private byte[] |
buffer
The buffer which will be filled from the datagram socket and then be used to supply the information when decoding data. |
private int |
bufferFragmentHeaderIndex
Index of fragment header within buffer . |
private int |
bufferHighmark
Index of the last four byte word in the buffer . |
private int |
bufferIndex
The write pointer is an index into the buffer . |
private static byte[] |
paddingZeros
Some zeros, only needed for padding -- like in real life. |
private java.net.Socket |
socket
The streaming socket to be used when receiving this XDR stream's buffer contents. |
(package private) java.io.OutputStream |
stream
The output stream used to get rid of bytes going off to the network. |
Constructor Summary | |
---|---|
XdrTcpEncodingStream(java.net.Socket streamingSocket,
int bufferSize)
Construct a new XdrTcpEncodingStream object and associate
it with the given streamingSocket for TCP/IP-based
communication. |
Method Summary | |
---|---|
void |
beginEncoding(java.net.InetAddress receiverAddress,
int receiverPort)
Begins encoding a new XDR record. |
void |
close()
Closes this encoding XDR stream and releases any system resources associated with this stream. |
void |
endEncoding()
Flushes this encoding XDR stream and forces any buffered output bytes to be written out. |
void |
endEncoding(boolean flush)
Ends the current record fort this encoding XDR stream. |
private void |
flush(boolean lastFragment,
boolean batch)
Flushes the current contents of the buffer as one fragment to the network. |
java.net.InetAddress |
getSenderAddress()
Returns the Internet address of the sender of the current XDR data. |
int |
getSenderPort()
Returns the port number of the sender of the current XDR data. |
void |
xdrEncodeInt(int value)
Encodes (aka "serializes") a "XDR int" value and writes it down a XDR stream. |
void |
xdrEncodeOpaque(byte[] value,
int offset,
int length)
Encodes (aka "serializes") a XDR opaque value, which is represented by a vector of byte values, and starts at offset with a
length of length . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.net.Socket socket
java.io.OutputStream stream
private byte[] buffer
private int bufferIndex
buffer
.
private int bufferHighmark
buffer
.
private int bufferFragmentHeaderIndex
buffer
.
private static final byte[] paddingZeros
Constructor Detail |
---|
public XdrTcpEncodingStream(java.net.Socket streamingSocket, int bufferSize) throws java.io.IOException
XdrTcpEncodingStream
object and associate
it with the given streamingSocket
for TCP/IP-based
communication.
streamingSocket
- Socket to which XDR data is sent.bufferSize
- Size of packet buffer for temporarily storing
outgoing XDR data.
java.io.IOException
Method Detail |
---|
public java.net.InetAddress getSenderAddress()
beginEncoding(java.net.InetAddress, int)
,
otherwise it might return stale information.
public int getSenderPort()
beginEncoding(java.net.InetAddress, int)
,
otherwise it might return stale information.
public void beginEncoding(java.net.InetAddress receiverAddress, int receiverPort) throws OncRpcException, java.io.IOException
beginEncoding
in class XdrEncodingStream
receiverAddress
- Indicates the receiver of the XDR data. This can be
null
for XDR streams connected permanently to a
receiver (like in case of TCP/IP based XDR streams).receiverPort
- Port number of the receiver.
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.public void endEncoding() throws OncRpcException, java.io.IOException
endEncoding
is that
calling it is an indication that the current record is finished and any
bytes previously encoded should immediately be written to their intended
destination.
endEncoding
in class XdrEncodingStream
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.public void endEncoding(boolean flush) throws OncRpcException, java.io.IOException
flush
is true
any buffered output bytes are
immediately written to their intended destination. If flush
is false
, then more than one record can be pipelined, for
instance, to batch several ONC/RPC calls. In this case the ONC/RPC
server must not send a reply (with the exception for the last
call in a batch, which might be trigger a reply). Otherwise, you will
most probably cause an interaction deadlock between client and server.
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.private void flush(boolean lastFragment, boolean batch) throws OncRpcException, java.io.IOException
lastFragment
- true
if this is the last fragment of
the current XDR record.batch
- if last fragment and batch
is
true
, then the buffer is not flushed to the network
but instead we wait for more records to be encoded.
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.public void close() throws OncRpcException, java.io.IOException
close
is that it closes the encoding XDR stream. A closed XDR stream cannot
perform encoding operations and cannot be reopened.
close
in class XdrEncodingStream
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.public void xdrEncodeInt(int value) throws OncRpcException, java.io.IOException
xdrEncodeInt
in class XdrEncodingStream
value
- The int value to be encoded.
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.public void xdrEncodeOpaque(byte[] value, int offset, int length) throws OncRpcException, java.io.IOException
offset
with a
length of length
. Only the opaque value is encoded, but
no length indication is preceeding the opaque value, so the receiver
has to know how long the opaque value will be. The encoded data is
always padded to be a multiple of four. If the given length is not a
multiple of four, zero bytes will be used for padding.
xdrEncodeOpaque
in class XdrEncodingStream
value
- The opaque value to be encoded in the form of a series of
bytes.offset
- Start offset in the data.length
- the number of bytes to encode.
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |