An OutputStream is created using the following function:
{zcode:cs}
namespace Ice
{
public sealed class Util
{
public static OutputStream createOutputStream(Communicator communicator);
}
}
{zcode} |
The OutputStream class is shown below.
{zcode:cs}
namespace Ice
{
public interface OutputStream
{
Communicator communicator();
void writeBool(bool v);
void writeBoolSeq(bool[] v);
void writeByte(byte v);
void writeByteSeq(byte[] v);
void writeShort(short v);
void writeShortSeq(short[] v);
void writeInt(int v);
void writeIntSeq(int[] v);
void writeLong(long v);
void writeLongSeq(long[] v);
void writeFloat(float v);
void writeFloatSeq(float[] v);
void writeDouble(double v);
void writeDoubleSeq(double[] v);
void writeString(string v);
void writeStringSeq(string[] v);
void writeSize(int sz);
void writeProxy(ObjectPrx v);
void writeObject(Ice.Object v);
void writeTypeId(string id);
void writeException(UserException ex);
void startSlice();
void endSlice();
void startEncapsulation();
void endEncapsulation();
void writePendingObjects();
byte[] finished();
void reset(bool clearBuffer);
void writeSerializable(object v);
void destroy();
}
}
{zcode} |
Member functions are provided for inserting 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 writeSize(int sz)void writeObject(Ice.Object v)writePendingObjects is invoked on the stream.void writeProxy(Ice.ObjectPrx v)void writeTypeId(string id)writeTypeId may only be invoked in the context of a call to writePendingObjects (see below).void writeException(UserException ex)void startEncapsulation()void endEncapsulation() void writePendingObjects()writeObject. This member function must only be called once.byte[] finished()void reset(boolean clearBuffer)clearBuffer determines whether the stream releases the internal buffer it allocated to hold the encoded data. If clearBuffer is true, the stream releases the buffer in order to make it eligible for garbage collection. If clearBuffer is false, the stream retains the buffer to avoid generating unnecessary garbage.void writeSerializable(object v)void destroy()Here is a simple example that demonstrates how to insert a boolean and a sequence of strings into a stream:
{zcode:cs}
string[] seq = { "Ice", "rocks!" };
Ice.OutputStream outStream
= Ice.Util.createOutputStream(communicator);
try {
outStream.writeBool(true);
outStream.writeStringSeq(seq);
byte[] data = outStream.finished();
} finally {
outStream.destroy();
}
{zcode} |