An InputStream is created using the following function:

{zcode:cs}
namespace Ice
{
    public sealed class Util
    {
        public static InputStream createInputStream(
            Communicator communicator,
            byte[] bytes);
 
        public static InputStream createInputStream(
            Communicator communicator,
            byte[] bytes,
            EncodingVersion version);
 
        public static InputStream wrapInputStream(
            Communicator communicator,
            byte[] bytes);
 
        public static InputStream wrapInputStream(
            Communicator communicator,
            byte[] bytes,
            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 memory buffer remains unmodified for the lifetime of the InputStream object.

The InputStream interface is shown below.

{zcode:cs}
namespace Ice
{
    public interface InputStream
    {
        Communicator communicator();

        void sliceObjects(bool slice);

        bool readBool();
        bool[] 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 minSize);

        ObjectPrx readProxy();

        void readObject(ReadObjectCallback cb);

        int readEnum(int maxValue);

        void throwException();
        void throwException(UserExceptionReaderFactory factory);

        void startObject();
        SlicedData endObject(bool preserve);
 
        void startException();
        SlicedData endException(bool preserve);

        string startSlice();
        void endSlice();
        void skipSlice();

        EncodingVersion startEncapsulation();
        void endEncapsulation();
        EncodingVersion skipEncapsulation();
        EncodingVersion getEncoding();

        void readPendingObjects();

        object readSerializable();

        void rewind();

        void skip(int sz);
        void skipSize();
 
        bool 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:cs}
byte[] data = ...
Ice.InputStream inStream =
    Ice.Util.createInputStream(communicator, data);
try {
    bool b = inStream.readBool();
    string[] seq = inStream.readStringSeq();
} finally {
    inStream.destroy();
}
{zcode}

See Also