Package org.acplt.oncrpc
Class XdrBufferDecodingStream
- java.lang.Object
-
- org.acplt.oncrpc.XdrDecodingStream
-
- org.acplt.oncrpc.XdrBufferDecodingStream
-
public class XdrBufferDecodingStream extends XdrDecodingStream
TheXdrBufferDecodingStreamclass provides the necessary functionality toXdrDecodingStreamto retrieve XDR packets from a byte buffer.- Version:
- $Revision: 1.2 $ $Date: 2005/11/11 21:06:36 $ $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 intbufferHighmarkIndex of the last four byte word in the buffer, which has been read in from the datagram socket.private intbufferIndexThe read pointer is an index into thebuffer.private intencodedLengthLength of encoded data inbuffer.
-
Constructor Summary
Constructors Constructor Description XdrBufferDecodingStream(byte[] buffer)Construct a newXdrUdpDecodingStreamobject and associate it with a buffer containing encoded XDR data.XdrBufferDecodingStream(byte[] buffer, int encodedLength)Construct a newXdrUdpDecodingStreamobject and associate it with a buffer containing encoded XDR data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginDecoding()Initiates decoding of the next XDR record.voidclose()Closes this decoding XDR stream and releases any system resources associated with this stream.voidendDecoding()End decoding of the current XDR record.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.voidsetXdrData(byte[] buffer, int encodedLength)Sets the buffer containing encoded XDR data as well as the length of the encoded data.intxdrDecodeInt()Decodes (aka "deserializes") a "XDR int" value received from a XDR stream.voidxdrDecodeOpaque(byte[] opaque, int offset, int length)Decodes (aka "deserializes") a XDR opaque value, which is represented by a vector of byte values, and starts atoffsetwith a length oflength.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
-
-
-
-
Field Detail
-
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.
-
encodedLength
private int encodedLength
Length of encoded data inbuffer.
-
bufferIndex
private int bufferIndex
The read pointer is an index into thebuffer.
-
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
-
XdrBufferDecodingStream
public XdrBufferDecodingStream(byte[] buffer, int encodedLength)Construct a newXdrUdpDecodingStreamobject and associate it with a buffer containing encoded XDR data.- Parameters:
buffer- Buffer containing encoded XDR data.encodedLength- Length of encoded XDR data within the buffer.- Throws:
java.lang.IllegalArgumentException- ifencodedLengthis not a multiple of four.
-
XdrBufferDecodingStream
public XdrBufferDecodingStream(byte[] buffer)
Construct a newXdrUdpDecodingStreamobject and associate it with a buffer containing encoded XDR data.- Parameters:
buffer- Buffer containing encoded XDR data.- Throws:
java.lang.IllegalArgumentException- if the size of the buffer is not a multiple of four.
-
-
Method Detail
-
setXdrData
public void setXdrData(byte[] buffer, int encodedLength)Sets the buffer containing encoded XDR data as well as the length of the encoded data.- Parameters:
buffer- Buffer containing encoded XDR data.encodedLength- Length of encoded XDR data within the buffer.- Throws:
java.lang.IllegalArgumentException- ifencodedLengthis not a multiple of four.
-
getSenderAddress
public java.net.InetAddress getSenderAddress()
Returns the Internet address of the sender of the current XDR data. This method should only be called afterbeginDecoding(), otherwise it might return stale information.- Specified by:
getSenderAddressin classXdrDecodingStream- 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 afterbeginDecoding(), otherwise it might return stale information.- Specified by:
getSenderPortin classXdrDecodingStream- Returns:
- Port number of the sender of the current XDR data.
-
beginDecoding
public void beginDecoding() throws OncRpcException, java.io.IOExceptionInitiates decoding of the next XDR record.- Specified by:
beginDecodingin classXdrDecodingStream- 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.IOExceptionEnd decoding of the current XDR record. The general contract ofendDecodingis 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:
endDecodingin classXdrDecodingStream- 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 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.
- Overrides:
closein classXdrDecodingStream- 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.IOExceptionDecodes (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:
xdrDecodeIntin classXdrDecodingStream- 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.IOExceptionDecodes (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 fromxdrDecodeOpaque(byte[], int, int)where first the length of the opaque value is retrieved from the XDR stream.- Specified by:
xdrDecodeOpaquein classXdrDecodingStream- 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.IOExceptionDecodes (aka "deserializes") a XDR opaque value, which is represented by a vector of byte values, and starts atoffsetwith a length oflength. 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:
xdrDecodeOpaquein classXdrDecodingStream- 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.
-
-