Package org.acplt.oncrpc
Class XdrBufferEncodingStream
java.lang.Object
org.acplt.oncrpc.XdrEncodingStream
org.acplt.oncrpc.XdrBufferEncodingStream
The
XdrBufferEncodingStream
class provides a buffer-based
XDR stream.- Version:
- $Revision: 1.2 $ $Date: 2003/08/14 11:26:50 $ $State: Exp $ $Locker: $
- Author:
- Harald Albrecht
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
The buffer which will receive the encoded information, before it is sent via a datagram socket.private int
Index of the last four byte word in the buffer.private int
The write pointer is an index into thebuffer
.private static final byte[]
Some zeros, only needed for padding -- like in real life. -
Constructor Summary
ConstructorsConstructorDescriptionXdrBufferEncodingStream
(byte[] buffer) Constructs a newXdrBufferEncodingStream
with a given buffer.XdrBufferEncodingStream
(int bufferSize) Constructs a newXdrBufferEncodingStream
with a buffer to encode data into of the given size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Flushes this encoding XDR stream and forces any buffered output bytes to be written out.byte[]
Returns the buffer holding encoded data.int
Returns the amount of encoded data in the buffer.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 atoffset
with 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 Details
-
buffer
private byte[] bufferThe buffer which will receive the encoded information, before it is sent via a datagram socket. -
bufferIndex
private int bufferIndexThe write pointer is an index into thebuffer
. -
bufferHighmark
private int bufferHighmarkIndex of the last four byte word in the buffer. -
paddingZeros
private static final byte[] paddingZerosSome zeros, only needed for padding -- like in real life.
-
-
Constructor Details
-
XdrBufferEncodingStream
public XdrBufferEncodingStream(int bufferSize) Constructs a newXdrBufferEncodingStream
with a buffer to encode data into of the given size.- Parameters:
bufferSize
- Size of buffer to store encoded data in.
-
XdrBufferEncodingStream
public XdrBufferEncodingStream(byte[] buffer) Constructs a newXdrBufferEncodingStream
with a given buffer.- Parameters:
buffer
- Buffer to store encoded information in.- Throws:
IllegalArgumentException
- ifencodedLength
is not a multiple of four.
-
-
Method Details
-
getXdrLength
public int getXdrLength()Returns the amount of encoded data in the buffer.- Returns:
- length of data encoded in buffer.
-
getXdrData
public byte[] getXdrData()Returns the buffer holding encoded data.- Returns:
- Buffer with encoded data.
-
beginEncoding
public void beginEncoding(InetAddress receiverAddress, int receiverPort) throws OncRpcException, IOException Begins encoding a new XDR record. This involves resetting this encoding XDR stream back into a known state.- Overrides:
beginEncoding
in classXdrEncodingStream
- Parameters:
receiverAddress
- Indicates the receiver of the XDR data. This can benull
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
Flushes this encoding XDR stream and forces any buffered output bytes to be written out. The general contract ofendEncoding
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 classXdrEncodingStream
- Throws:
OncRpcException
- if an ONC/RPC error occurs.IOException
- if an I/O error occurs.
-
close
Closes this encoding XDR stream and releases any system resources associated with this stream. The general contract ofclose
is that it closes the encoding XDR stream. A closed XDR stream cannot perform encoding operations and cannot be reopened.- Overrides:
close
in classXdrEncodingStream
- Throws:
OncRpcException
- if an ONC/RPC error occurs.IOException
- if an I/O error occurs.
-
xdrEncodeInt
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 classXdrEncodingStream
- 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 atoffset
with 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:
xdrEncodeOpaque
in 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.IOException
- if an I/O error occurs.
-