public class XdrBufferEncodingStream extends XdrEncodingStream
XdrBufferEncodingStream
class provides a buffer-based
XDR stream.Modifier and Type | Field and Description |
---|---|
private byte[] |
buffer
The buffer which will receive the encoded information, before it
is sent via a datagram socket.
|
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.
|
Constructor and Description |
---|
XdrBufferEncodingStream(byte[] buffer)
Constructs a new
XdrBufferEncodingStream with a given
buffer. |
XdrBufferEncodingStream(int bufferSize)
Constructs a new
XdrBufferEncodingStream with a buffer
to encode data into of the given size. |
Modifier and Type | Method and Description |
---|---|
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.
|
byte[] |
getXdrData()
Returns the buffer holding encoded data.
|
int |
getXdrLength()
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 at
offset with a
length of length . |
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
private byte[] buffer
private int bufferIndex
buffer
.private int bufferHighmark
private static final byte[] paddingZeros
public XdrBufferEncodingStream(int bufferSize)
XdrBufferEncodingStream
with a buffer
to encode data into of the given size.bufferSize
- Size of buffer to store encoded data in.public XdrBufferEncodingStream(byte[] buffer)
XdrBufferEncodingStream
with a given
buffer.buffer
- Buffer to store encoded information in.java.lang.IllegalArgumentException
- if encodedLength
is not
a multiple of four.public int getXdrLength()
public byte[] getXdrData()
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 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.