An InputStream
is created using the following function:
{zcode:java} package Ice; public class Util { public static InputStream createInputStream(Communicator communicator, byte[] data); } {zcode} |
The InputStream
interface is shown below.
{zcode:java} package Ice; public interface InputStream { Communicator communicator(); void sliceObjects(boolean slice); boolean readBool(); boolean[] readBoolSeq(); byte readByte(); byte[] readByteSeq(); short readShort(); short[] readShortSeq(); int readInt(); int[] readIntSeq(); long readLong(); long[] readLongSeq(); float readFloat(); float[] readFloatSeq(); double readDouble(); double[] readDoubleSeq(); String readString(); String[] readStringSeq(); int readSize(); int readAndCheckSeqSize(int minSizeWireSize); ObjectPrx readProxy(); void readObject(ReadObjectCallback cb); String readTypeId(); void throwException() throws UserException; void startSlice(); void endSlice(); void skipSlice(); void startEncapsulation(); void endEncapsulation(); void skipEncapsulation(); void readPendingObjects(); java.io.Serializable readSerializable(); void rewind(); void destroy(); } {zcode} |
Member functions are provided for extracting all of the primitive types, as well as sequences of primitive types; these are self-explanatory. The remaining member functions have the following semantics:
void sliceObjects(boolean slice)
Determines the behavior of the stream when extracting Ice objects. An Ice object is "sliced" when a factory cannot be found for a Slice type ID, resulting in the creation of an object of a less-derived type. Slicing is typically disabled when the application expects all object factories to be present, in which case the exception NoObjectFactoryException
is raised. The default behavior is to allow slicing.int readSize()
int readAndCheckSeqSize(int minWireSize)
readSize
, this function reads a size and returns it, but also verifies that there is enough data remaining in the unmarshaling buffer to successfully unmarshal the elements of the sequence. The minWireSize
parameter indicates the smallest possible on-the-wire representation of a single sequence element. If the unmarshaling buffer contains insufficient data to unmarshal the sequence, the function throws UnmarshalOutOfBoundsException
.Ice.ObjectPrx readProxy()
ObjectPrx
. The Slice compiler optionally generates helper functions to extract proxies of user-defined types.void readObject(ReadObjectCallback cb)
readObject
function accepts a callback object of type ReadObjectCallback
, whose definition is shown below:
{zcode:java} package Ice; public interface ReadObjectCallback { void invoke(Ice.Object obj); } {zcode} |
invoke
member function is called. The application must call readPendingObjects
to ensure that all instances are properly extracted. Note that applications rarely need to invoke this member function directly; the helper functions generated by the Slice compiler are easier to use.String readTypeId()
void throwException() throws UserException
UnmarshalOutOfBoundsException
is thrown.void startSlice()
void endSlice()
void skipSlice()
void startEncapsulation()
void endEncapsulation()
void skipEncapsulation()
void readPendingObjects()
readObject
).java.io.Serializable readSerializable()
void destroy()
Here is a simple example that demonstrates how to extract a boolean and a sequence of strings from a stream:
{zcode:java} byte[] data = ... Ice.InputStream in = Ice.Util.createInputStream(communicator, data); try { boolean b = in.readBool(); String[] seq = in.readStringSeq(); } finally { in.destroy(); } {zcode} |