Package org.acplt.oncrpc
Class XdrTcpEncodingStream
- java.lang.Object
-
- org.acplt.oncrpc.XdrEncodingStream
-
- org.acplt.oncrpc.XdrTcpEncodingStream
-
public class XdrTcpEncodingStream extends XdrEncodingStream
TheXdrTcpEncodingStreamclass provides the necessary functionality toXdrEncodingStreamto send XDR records to the network using the stream-oriented TCP/IP.- Version:
- $Revision: 1.2 $ $Date: 2003/08/14 11:07:39 $ $State: Exp $ $Locker: $
- Author:
- Harald Albrecht
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]bufferThe buffer which will be filled from the datagram socket and then be used to supply the information when decoding data.private intbufferFragmentHeaderIndexIndex of fragment header withinbuffer.private intbufferHighmarkIndex of the last four byte word in thebuffer.private intbufferIndexThe write pointer is an index into thebuffer.private static byte[]paddingZerosSome zeros, only needed for padding -- like in real life.private java.net.SocketsocketThe streaming socket to be used when receiving this XDR stream's buffer contents.(package private) java.io.OutputStreamstreamThe output stream used to get rid of bytes going off to the network.
-
Constructor Summary
Constructors Constructor Description XdrTcpEncodingStream(java.net.Socket streamingSocket, int bufferSize)Construct a newXdrTcpEncodingStreamobject and associate it with the givenstreamingSocketfor TCP/IP-based communication.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginEncoding(java.net.InetAddress receiverAddress, int receiverPort)Begins encoding a new XDR record.voidclose()Closes this encoding XDR stream and releases any system resources associated with this stream.voidendEncoding()Flushes this encoding XDR stream and forces any buffered output bytes to be written out.voidendEncoding(boolean flush)Ends the current record fort this encoding XDR stream.private voidflush(boolean lastFragment, boolean batch)Flushes the current contents of the buffer as one fragment to the network.java.net.InetAddressgetSenderAddress()Returns the Internet address of the sender of the current XDR data.intgetSenderPort()Returns the port number of the sender of the current XDR data.voidxdrEncodeInt(int value)Encodes (aka "serializes") a "XDR int" value and writes it down a XDR stream.voidxdrEncodeOpaque(byte[] value, int offset, int length)Encodes (aka "serializes") a XDR opaque value, which is represented by a vector of byte values, and starts atoffsetwith a length oflength.-
Methods inherited from class org.acplt.oncrpc.XdrEncodingStream
getCharacterEncoding, setCharacterEncoding, xdrEncodeBoolean, xdrEncodeBooleanFixedVector, xdrEncodeBooleanVector, xdrEncodeByte, xdrEncodeByteFixedVector, xdrEncodeByteVector, xdrEncodeDouble, xdrEncodeDoubleFixedVector, xdrEncodeDoubleVector, xdrEncodeDynamicOpaque, xdrEncodeFloat, xdrEncodeFloatFixedVector, xdrEncodeFloatVector, xdrEncodeIntFixedVector, xdrEncodeIntVector, xdrEncodeLong, xdrEncodeLongFixedVector, xdrEncodeLongVector, xdrEncodeOpaque, xdrEncodeOpaque, xdrEncodeShort, xdrEncodeShortFixedVector, xdrEncodeShortVector, xdrEncodeString, xdrEncodeStringFixedVector, xdrEncodeStringVector
-
-
-
-
Field Detail
-
socket
private java.net.Socket socket
The streaming socket to be used when receiving this XDR stream's buffer contents.
-
stream
java.io.OutputStream stream
The output stream used to get rid of bytes going off to the network.
-
buffer
private byte[] buffer
The buffer which will be filled from the datagram socket and then be used to supply the information when decoding data.
-
bufferIndex
private int bufferIndex
The write pointer is an index into thebuffer.
-
bufferHighmark
private int bufferHighmark
Index of the last four byte word in thebuffer.
-
bufferFragmentHeaderIndex
private int bufferFragmentHeaderIndex
Index of fragment header withinbuffer.
-
paddingZeros
private static final byte[] paddingZeros
Some zeros, only needed for padding -- like in real life.
-
-
Constructor Detail
-
XdrTcpEncodingStream
public XdrTcpEncodingStream(java.net.Socket streamingSocket, int bufferSize) throws java.io.IOExceptionConstruct a newXdrTcpEncodingStreamobject and associate it with the givenstreamingSocketfor TCP/IP-based communication.- Parameters:
streamingSocket- Socket to which XDR data is sent.bufferSize- Size of packet buffer for temporarily storing outgoing XDR data.- Throws:
java.io.IOException
-
-
Method Detail
-
getSenderAddress
public java.net.InetAddress getSenderAddress()
Returns the Internet address of the sender of the current XDR data. This method should only be called afterbeginEncoding(java.net.InetAddress, int), otherwise it might return stale information.- Returns:
- InetAddress of the sender of the current XDR data.
-
getSenderPort
public int getSenderPort()
Returns the port number of the sender of the current XDR data. This method should only be called afterbeginEncoding(java.net.InetAddress, int), otherwise it might return stale information.- Returns:
- Port number of the sender of the current XDR data.
-
beginEncoding
public void beginEncoding(java.net.InetAddress receiverAddress, int receiverPort) throws OncRpcException, java.io.IOExceptionBegins encoding a new XDR record. This typically involves resetting this encoding XDR stream back into a known state.- Overrides:
beginEncodingin classXdrEncodingStream- Parameters:
receiverAddress- Indicates the receiver of the XDR data. This can benullfor XDR streams connected permanently to a receiver (like in case of TCP/IP based XDR streams).receiverPort- Port number of the receiver.- Throws:
OncRpcException- if an ONC/RPC error occurs.java.io.IOException- if an I/O error occurs.
-
endEncoding
public void endEncoding() throws OncRpcException, java.io.IOExceptionFlushes this encoding XDR stream and forces any buffered output bytes to be written out. The general contract ofendEncodingis 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.- Overrides:
endEncodingin classXdrEncodingStream- Throws:
OncRpcException- if an ONC/RPC error occurs.java.io.IOException- if an I/O error occurs.
-
endEncoding
public void endEncoding(boolean flush) throws OncRpcException, java.io.IOExceptionEnds the current record fort this encoding XDR stream. If the parameterflushistrueany buffered output bytes are immediately written to their intended destination. Ifflushisfalse, 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.- Throws:
OncRpcException- if an ONC/RPC error occurs.java.io.IOException- if an I/O error occurs.
-
flush
private void flush(boolean lastFragment, boolean batch) throws OncRpcException, java.io.IOExceptionFlushes the current contents of the buffer as one fragment to the network.- Parameters:
lastFragment-trueif this is the last fragment of the current XDR record.batch- if last fragment andbatchistrue, then the buffer is not flushed to the network but instead we wait for more records to be encoded.- Throws:
OncRpcException- if an ONC/RPC error occurs.java.io.IOException- if an I/O error occurs.
-
close
public void close() throws OncRpcException, java.io.IOExceptionCloses this encoding XDR stream and releases any system resources associated with this stream. The general contract ofcloseis that it closes the encoding XDR stream. A closed XDR stream cannot perform encoding operations and cannot be reopened.- Overrides:
closein classXdrEncodingStream- Throws:
OncRpcException- if an ONC/RPC error occurs.java.io.IOException- if an I/O error occurs.
-
xdrEncodeInt
public void xdrEncodeInt(int value) throws OncRpcException, java.io.IOExceptionEncodes (aka "serializes") a "XDR int" value and writes it down a XDR stream. A XDR int is 32 bits wide -- the same width Java's "int" data type has. This method is one of the basic methods all other methods can rely on.- Specified by:
xdrEncodeIntin classXdrEncodingStream- Parameters:
value- The int value to be encoded.- Throws:
OncRpcException- if an ONC/RPC error occurs.java.io.IOException- if an I/O error occurs.
-
xdrEncodeOpaque
public void xdrEncodeOpaque(byte[] value, int offset, int length) throws OncRpcException, java.io.IOExceptionEncodes (aka "serializes") a XDR opaque value, which is represented by a vector of byte values, and starts atoffsetwith a length oflength. 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.- Specified by:
xdrEncodeOpaquein classXdrEncodingStream- Parameters:
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.- Throws:
OncRpcException- if an ONC/RPC error occurs.java.io.IOException- if an I/O error occurs.
-
-