Package org.acplt.oncrpc

# Class XdrTcpEncodingStream

java.lang.Object
org.acplt.oncrpc.XdrEncodingStream
org.acplt.oncrpc.XdrTcpEncodingStream

public class XdrTcpEncodingStream extends XdrEncodingStream
The `XdrTcpEncodingStream` class provides the necessary functionality to `XdrEncodingStream` to 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

## Constructor Summary

Constructors
Constructor
Description
`XdrTcpEncodingStream(Socket streamingSocket, int bufferSize)`
Construct a new `XdrTcpEncodingStream` object and associate it with the given `streamingSocket` for TCP/IP-based communication.

## Method Summary

Modifier and Type
Method
Description
`void`
`beginEncoding(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.
`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 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`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### XdrTcpEncodingStream

public XdrTcpEncodingStream(Socket streamingSocket, int bufferSize) throws IOException
Construct a new `XdrTcpEncodingStream` object and associate it with the given `streamingSocket` for 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:
  `IOException` - if the passed socket instance fails to provide an output stream.

## Method Details

### getSenderAddress

public InetAddress getSenderAddress()
Returns the Internet address of the sender of the current XDR data. This method should only be called after `beginEncoding(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 after `beginEncoding(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(InetAddress receiverAddress, int receiverPort) throws OncRpcException, IOException
Begins encoding a new XDR record. This typically involves resetting this encoding XDR stream back into a known state.

Overrides:
  `beginEncoding` in class `XdrEncodingStream`
Parameters:
  `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.
Throws:
  `OncRpcException` - if an ONC/RPC error occurs.
  `IOException` - if an I/O error occurs.

### endEncoding

public void endEncoding() throws OncRpcException, IOException
Flushes this encoding XDR stream and forces any buffered output bytes to be written out. The general contract of `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.

Overrides:
  `endEncoding` in class `XdrEncodingStream`
Throws:
  `OncRpcException` - if an ONC/RPC error occurs.
  `IOException` - if an I/O error occurs.

### endEncoding

public void endEncoding(boolean flush) throws OncRpcException, IOException
Ends the current record fort this encoding XDR stream. If the parameter `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.

Parameters:
  `flush` - Whether to flush then actual stream content immediately or to wait for further records.
Throws:
  `OncRpcException` - if an ONC/RPC error occurs.
  `IOException` - if an I/O error occurs.

### close

public void close() throws OncRpcException, IOException
Closes this encoding XDR stream and releases any system resources associated with this stream. The general contract of `close` is that it closes the encoding XDR stream. A closed XDR stream cannot perform encoding operations and cannot be reopened.

Overrides:
  `close` in class `XdrEncodingStream`
Throws:
  `OncRpcException` - if an ONC/RPC error occurs.
  `IOException` - if an I/O error occurs.

### xdrEncodeInt

public void xdrEncodeInt(int value) throws OncRpcException, IOException
Encodes (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:
  `xdrEncodeInt` in class `XdrEncodingStream`
Parameters:
  `value` - The int value to be encoded.
Throws:
  `OncRpcException` - if an ONC/RPC error occurs.
  `IOException` - if an I/O error occurs.

### xdrEncodeOpaque

public void xdrEncodeOpaque(byte[] value, int offset, int length) throws OncRpcException, IOException
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`. 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:
  `xdrEncodeOpaque` in class `XdrEncodingStream`
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.
  `IOException` - if an I/O error occurs.