org.acplt.oncrpc

## Class XdrUdpDecodingStream

- java.lang.Object
- - org.acplt.oncrpc.XdrDecodingStream
  - - org.acplt.oncrpc.XdrUdpDecodingStream

    public class XdrUdpDecodingStream
    extends XdrDecodingStream

The `XdrUdpDecodingStream` class provides the necessary functionality to `XdrDecodingStream` to receive XDR packets from the network using the datagram-oriented UDP/IP.

Version:
  $Revision: 1.2 $ $Date: 2005/11/11 21:07:40 $ $State: Exp $ $Locker: $
Author:
  Harald Albrecht

### Field Summary

Fields
`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` `bufferHighmark` Index of the last four byte word in the buffer, which has been read in from the datagram socket.
`private int` `bufferIndex` The read pointer is an index into the `buffer`.
`private java.net.InetAddress` `senderAddress` Sender's address of current buffer contents.
`private int` `senderPort` The senders's port.
`private java.net.DatagramSocket` `socket` The datagram socket to be used when receiving this XDR stream's buffer contents.

### Constructor Summary

Constructors
Constructor and Description
`XdrUdpDecodingStream(java.net.DatagramSocket datagramSocket, int bufferSize)` Construct a new `XdrUdpDecodingStream` object and associate it with the given `datagramSocket` for UDP/IP-based communication.

### Method Summary

Methods
`void` `beginDecoding()` Initiates decoding of the next XDR record.
`void` `close()` Closes this decoding XDR stream and releases any system resources associated with this stream.
`void` `endDecoding()` End decoding of the current XDR record.
`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.
`int` `xdrDecodeInt()` Decodes (aka "deserializes") a "XDR int" value received from a XDR stream.
`void` `xdrDecodeOpaque(byte[] opaque, int offset, int length)` Decodes (aka "deserializes") a XDR opaque value, which is represented by a vector of byte values, and starts at `offset` with a length of `length`.
`byte[]` `xdrDecodeOpaque(int length)` Decodes (aka "deserializes") an opaque value, which is nothing more than a series of octets (or 8 bits wide bytes).

### Methods inherited from class org.acplt.oncrpc.XdrDecodingStream

`getCharacterEncoding, setCharacterEncoding, xdrDecodeBoolean, xdrDecodeBooleanFixedVector, xdrDecodeBooleanVector, xdrDecodeByte, xdrDecodeByteFixedVector, xdrDecodeByteVector, xdrDecodeDouble, xdrDecodeDoubleFixedVector, xdrDecodeDoubleVector, xdrDecodeDynamicOpaque, xdrDecodeFloat, xdrDecodeFloatFixedVector, xdrDecodeFloatVector, xdrDecodeIntFixedVector, xdrDecodeIntVector, xdrDecodeLong, xdrDecodeLongFixedVector, xdrDecodeLongVector, xdrDecodeOpaque, xdrDecodeShort, xdrDecodeShortFixedVector, xdrDecodeShortVector, xdrDecodeString, xdrDecodeStringFixedVector, xdrDecodeStringVector`

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

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

### Field Detail

#### socket

    private java.net.DatagramSocket socket

The datagram socket to be used when receiving this XDR stream's buffer contents.

#### senderAddress

    private java.net.InetAddress senderAddress

Sender's address of current buffer contents.

#### senderPort

    private int senderPort

The senders's port.

#### 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 read pointer is an index into the `buffer`.

#### bufferHighmark

    private int bufferHighmark

Index of the last four byte word in the buffer, which has been read in from the datagram socket.

### Constructor Detail

#### XdrUdpDecodingStream

    public XdrUdpDecodingStream(java.net.DatagramSocket datagramSocket,
                        int bufferSize)

Construct a new `XdrUdpDecodingStream` object and associate it with the given `datagramSocket` for UDP/IP-based communication. This constructor is typically used when communicating with servers over UDP/IP using a "connected" datagram socket.

Parameters:
  `datagramSocket` - Datagram socket from which XDR data is received.
  `bufferSize` - Size of packet buffer for storing received XDR datagrams.

### 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 after `beginDecoding()`, otherwise it might return stale information.

Specified by:
  `getSenderAddress` in class `XdrDecodingStream`
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 `beginDecoding()`, otherwise it might return stale information.

Specified by:
  `getSenderPort` in class `XdrDecodingStream`
Returns:
  Port number of the sender of the current XDR data.

#### beginDecoding

    public void beginDecoding()
                       throws OncRpcException,
                              java.io.IOException

Initiates decoding of the next XDR record. For UDP-based XDR decoding streams this reads in the next datagram from the network socket.

Specified by:
  `beginDecoding` in class `XdrDecodingStream`
Throws:
  `OncRpcException` - if an ONC/RPC error occurs.
  `java.io.IOException` - if an I/O error occurs.

#### endDecoding

    public void endDecoding()
                     throws OncRpcException,
                            java.io.IOException

End decoding of the current XDR record. The general contract of `endDecoding` is that calling it is an indication that the current record is no more interesting to the caller and any allocated data for this record can be freed.

This method overrides `XdrDecodingStream.endDecoding()`. It does nothing more than resetting the buffer pointer (eeek! a pointer in Java!!!) back to the begin of an empty buffer, so attempts to decode data will fail until the buffer is filled again.

Overrides:
  `endDecoding` in class `XdrDecodingStream`
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.IOException

Closes this decoding XDR stream and releases any system resources associated with this stream. A closed XDR stream cannot perform decoding operations and cannot be reopened.

This implementation frees the allocated buffer but does not close the associated datagram socket. It only throws away the reference to this socket.

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

#### xdrDecodeInt

    public int xdrDecodeInt()
                     throws OncRpcException,
                            java.io.IOException

Decodes (aka "deserializes") a "XDR int" value received from a XDR stream. A XDR int is 32 bits wide -- the same width Java's "int" data type has.

Specified by:
  `xdrDecodeInt` in class `XdrDecodingStream`
Returns:
  The decoded int value.
Throws:
  `OncRpcException` - if an ONC/RPC error occurs.
  `java.io.IOException` - if an I/O error occurs.

#### xdrDecodeOpaque

    public byte[] xdrDecodeOpaque(int length)
                           throws OncRpcException,
                                  java.io.IOException

Decodes (aka "deserializes") an opaque value, which is nothing more than a series of octets (or 8 bits wide bytes). Because the length of the opaque value is given, we don't need to retrieve it from the XDR stream. This is different from `xdrDecodeOpaque(byte[], int, int)` where first the length of the opaque value is retrieved from the XDR stream.

Specified by:
  `xdrDecodeOpaque` in class `XdrDecodingStream`
Parameters:
  `length` - Length of opaque data to decode.
Returns:
  Opaque data as a byte vector.
Throws:
  `OncRpcException` - if an ONC/RPC error occurs.
  `java.io.IOException` - if an I/O error occurs.

#### xdrDecodeOpaque

    public void xdrDecodeOpaque(byte[] opaque,
                       int offset,
                       int length)
                         throws OncRpcException,
                                java.io.IOException

Decodes (aka "deserializes") 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 decoded, so the caller has to know how long the opaque value will be. The decoded data is always padded to be a multiple of four (because that's what the sender does).

Specified by:
  `xdrDecodeOpaque` in class `XdrDecodingStream`
Parameters:
  `opaque` - Byte vector which will receive the decoded opaque value.
  `offset` - Start offset in the byte vector.
  `length` - the number of bytes to decode.
Throws:
  `OncRpcException` - if an ONC/RPC error occurs.
  `java.io.IOException` - if an I/O error occurs.