An InputStream is created using the following functions:

{zcode:java}
package Ice;

public class Util {
    public static InputStream
    createInputStream(Communicator communicator, byte[] data);
 
    public static InputStream
    createInputStream(Communicator communicator, byte[] data, EncodingVersion version);
 
    public static InputStream
    wrapInputStream(Communicator communicator, byte[] data);
 
    public static InputStream
    wrapInputStream(Communicator communicator, byte[] data, EncodingVersion version);
}
{zcode}

You can optionally specify an encoding version for the stream, otherwise the stream uses the communicator's default encoding version.

Note that the createInputStream functions make a copy of the supplied data, whereas the wrapInputStream functions avoid copies by keeping a reference to the data. If you use wrapInputStream, it is your responsibility to ensure that the byte array remains unmodified for the lifetime of the InputStream object.

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);

    int readEnum(int maxValue);
 
    void throwException() throws UserException;
    void throwException(UserExceptionReaderFactory factory) throws UserException;
 
    void startObject();
    SlicedData endObject(boolean preserve);
 
    void startException();
    SlicedData endException(boolean preserve);

    String startSlice();
    void endSlice();
    void skipSlice();

    EncodingVersion startEncapsulation();
    void endEncapsulation();
    EncodingVersion skipEncapsulation();
 
    EncodingVersion getEncoding();
 
    void readPendingObjects();
    java.io.Serializable readSerializable();

    void rewind();

    void skip(int sz);
    void skipSize();
 
    boolean readOptional(int tag, OptionalFormat format);
 
    int pos();
 
    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:

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}

See Also