|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.acplt.oncrpc.XdrDecodingStream org.acplt.oncrpc.XdrTcpDecodingStream
public class XdrTcpDecodingStream
The XdrTcpDecodingStream
class provides the necessary
functionality to XdrDecodingStream
to receive XDR records from the
network using the stream-oriented TCP/IP.
Field Summary | |
---|---|
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 int |
fragmentLength
Remaining number of bytes in this fragment -- and still to read. |
private boolean |
lastFragment
Flag indicating that we've read the last fragment and thus reached the end of the record. |
private java.net.Socket |
socket
The streaming socket to be used when receiving this XDR stream's buffer contents. |
(package private) java.io.InputStream |
stream
The input stream used to pull the bytes off the network. |
Constructor Summary | |
---|---|
XdrTcpDecodingStream(java.net.Socket streamingSocket,
int bufferSize)
Construct a new XdrTcpDecodingStream object and associate
it with the given streamingSocket for TCP/IP-based
communication. |
Method Summary | |
---|---|
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. |
private void |
fill()
Fills the internal buffer with the next chunk of data. |
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. |
private void |
readBuffer(java.io.InputStream stream,
byte[] bytes,
int bytesToRead)
Read into buffer exactly the amound of bytes specified. |
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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.net.Socket socket
java.io.InputStream stream
private byte[] buffer
private int bufferIndex
buffer
.
private int bufferHighmark
private int fragmentLength
private boolean lastFragment
Constructor Detail |
---|
public XdrTcpDecodingStream(java.net.Socket streamingSocket, int bufferSize) throws java.io.IOException
XdrTcpDecodingStream
object and associate
it with the given streamingSocket
for TCP/IP-based
communication.
streamingSocket
- Socket from which XDR data is received.bufferSize
- Size of packet buffer for storing received XDR
data.
java.io.IOException
Method Detail |
---|
public java.net.InetAddress getSenderAddress()
beginDecoding()
, otherwise
it might return stale information.
getSenderAddress
in class XdrDecodingStream
public int getSenderPort()
beginDecoding()
, otherwise
it might return stale information.
getSenderPort
in class XdrDecodingStream
public void beginDecoding() throws OncRpcException, java.io.IOException
Read in the next bunch of bytes. This can be either a complete fragment, or if the fragments sent by the communication partner are too large for our buffer, only parts of fragments. In every case, this method ensures that there will be more data available in the buffer (or else an exception thrown).
beginDecoding
in class XdrDecodingStream
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.private void readBuffer(java.io.InputStream stream, byte[] bytes, int bytesToRead) throws java.io.IOException, OncRpcException
stream
- Input stream to read byte data from.bytes
- buffer receiving data.bytesToRead
- number of bytes to read into buffer.
OncRpcException
- if EOF is reached before all bytes could
be read.
java.io.IOException
- if an I/O error occurs.private void fill() throws OncRpcException, java.io.IOException
This method does not accept empty XDR record fragments with the only exception of a final trailing empty fragment. This special case is accepted as some ONC/RPC implementations emit such trailing empty fragments whenever the encoded data is a full multiple of their internal record buffer size.
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.public void endDecoding() throws OncRpcException, java.io.IOException
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 reads in
and throws away fragments until it reaches the last fragment.
endDecoding
in class XdrDecodingStream
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.public void close() throws OncRpcException, java.io.IOException
This implementation frees the allocated buffer but does not close the associated datagram socket. It only throws away the reference to this socket.
close
in class XdrDecodingStream
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.public int xdrDecodeInt() throws OncRpcException, java.io.IOException
xdrDecodeInt
in class XdrDecodingStream
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.public byte[] xdrDecodeOpaque(int length) throws OncRpcException, java.io.IOException
xdrDecodeOpaque(byte[], int, int)
where
first the length of the opaque value is retrieved from the XDR stream.
xdrDecodeOpaque
in class XdrDecodingStream
length
- Length of opaque data to decode.
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.public void xdrDecodeOpaque(byte[] opaque, int offset, int length) throws OncRpcException, java.io.IOException
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).
xdrDecodeOpaque
in class XdrDecodingStream
opaque
- Byte vector which will receive the decoded opaque value.offset
- Start offset in the byte vector.length
- the number of bytes to decode.
OncRpcException
- if an ONC/RPC error occurs.
java.io.IOException
- if an I/O error occurs.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |