Package com.zeroc.Ice

Class OutputStream

java.lang.Object
com.zeroc.Ice.OutputStream

public final class OutputStream extends Object
Interface to marshal (write) Slice types into sequence of bytes encoded using the Slice encoding.
See Also:
  • Constructor Details

    • OutputStream

      public OutputStream()
      Construct a new instance of the OutputStream class. The output stream is initially empty, and uses the 1.1 encoding, and compact class format.
    • OutputStream

      public OutputStream(EncodingVersion encoding)
      Construct a new instance of the OutputStream class. The output stream is initially empty, and uses the specified encoding, and compact class format.
      Parameters:
      encoding - The encoding version to use.
    • OutputStream

      public OutputStream(EncodingVersion encoding, boolean direct)
      Construct a new instance of the OutputStream class. The output stream is initially empty, and uses the specified encoding, and compact class format.
      Parameters:
      encoding - The encoding version to use.
      direct - Indicates whether to use a direct buffer.
    • OutputStream

      public OutputStream(EncodingVersion encoding, FormatType format, boolean direct)
      Construct a new instance of the OutputStream class. The output stream is initially empty, and uses the specified encoding, and class format.
      Parameters:
      encoding - The encoding version to use.
      format - The format to use for class encoding.
      direct - Indicates whether to use a direct buffer.
    • OutputStream

      public OutputStream(Communicator communicator)
      Construct a new instance of the OutputStream class. The output stream is initially empty, and uses the communicator's default encoding version and default class format.
      Parameters:
      communicator - The communicator that provides the encoding version and class format.
  • Method Details

    • reset

      public void reset()
      Resets this output stream. This method allows the stream to be reused, to avoid creating unnecessary garbage.
    • clear

      public void clear()
      Releases any data retained by encapsulations. The reset() method internally calls clear.
    • finished

      public byte[] finished()
      Indicates that marshaling is finished.
      Returns:
      The byte sequence containing the encoded data.
    • swap

      public void swap(OutputStream other)
      Swaps the contents of one stream with another.
      Parameters:
      other - The other stream.
    • resize

      public void resize(int sz)
      Resizes the stream to a new size.
      Parameters:
      sz - The new size.
    • prepareWrite

      public com.zeroc.Ice.Buffer prepareWrite()
      Prepares the internal data buffer to be written to a socket.
      Returns:
      The internal buffer.
    • getBuffer

      public com.zeroc.Ice.Buffer getBuffer()
      Retrieves the internal data buffer.
      Returns:
      The buffer.
    • startValue

      public void startValue(SlicedData data)
      Marks the start of a class instance.
      Parameters:
      data - Preserved slices for this instance, or null.
    • endValue

      public void endValue()
      Marks the end of a class instance.
    • startException

      public void startException()
      Marks the start of a user exception.
    • endException

      public void endException()
      Marks the end of a user exception.
    • startEncapsulation

      public void startEncapsulation()
      Writes the start of an encapsulation to the stream.
    • startEncapsulation

      public void startEncapsulation(EncodingVersion encoding, FormatType format)
      Writes the start of an encapsulation to the stream.
      Parameters:
      encoding - The encoding version of the encapsulation.
      format - Specify the compact or sliced format, or null.
    • endEncapsulation

      public void endEncapsulation()
      Ends the previous encapsulation.
    • writeEmptyEncapsulation

      public void writeEmptyEncapsulation(EncodingVersion encoding)
      Writes an empty encapsulation using the given encoding version.
      Parameters:
      encoding - The desired encoding version.
    • writeEncapsulation

      public void writeEncapsulation(byte[] v)
      Writes a pre-encoded encapsulation.
      Parameters:
      v - The encapsulation data.
    • getEncoding

      public EncodingVersion getEncoding()
      Determines the current encoding version.
      Returns:
      The encoding version.
    • startSlice

      public void startSlice(String typeId, int compactId, boolean last)
      Marks the start of a new slice for a class instance or user exception.
      Parameters:
      typeId - The Slice type ID corresponding to this slice.
      compactId - The Slice compact type ID corresponding to this slice or -1 if no compact ID is defined for the type ID.
      last - True if this is the last slice, false otherwise.
    • endSlice

      public void endSlice()
      Marks the end of a slice for a class instance or user exception.
    • writePendingValues

      public void writePendingValues()
      Writes the state of Slice classes whose index was previously written with writeValue(com.zeroc.Ice.Value) to the stream.
    • writeSize

      public void writeSize(int v)
      Writes a size to the stream.
      Parameters:
      v - The size to write.
    • startSize

      public int startSize()
      Returns the current position and allocates four bytes for a fixed-length (32-bit) size value.
      Returns:
      The current position.
    • endSize

      public void endSize(int pos)
      Computes the amount of data written since the previous call to startSize and writes that value at the saved position.
      Parameters:
      pos - The saved position.
    • writeBlob

      public void writeBlob(byte[] v)
      Writes a blob of bytes to the stream.
      Parameters:
      v - The byte array to be written. All of the bytes in the array are written.
    • writeBlob

      public void writeBlob(byte[] v, int off, int len)
      Writes a blob of bytes to the stream.
      Parameters:
      v - The byte array to be written.
      off - The offset into the byte array from which to copy.
      len - The number of bytes from the byte array to copy.
    • writeOptional

      public boolean writeOptional(int tag, OptionalFormat format)
      Write the header information for an optional value.
      Parameters:
      tag - The numeric tag associated with the value.
      format - The optional format of the value.
      Returns:
      True if the current encoding supports optionals, false otherwise.
    • writeByte

      public void writeByte(byte v)
      Writes a byte to the stream.
      Parameters:
      v - The byte to write to the stream.
    • writeByte

      public void writeByte(int tag, Optional<Byte> v)
      Writes an optional byte to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional byte to write to the stream.
    • writeByte

      public void writeByte(int tag, byte v)
      Writes an optional byte to the stream.
      Parameters:
      tag - The optional tag.
      v - The byte to write to the stream.
    • rewriteByte

      public void rewriteByte(byte v, int dest)
      Writes a byte to the stream at the given position. The current position of the stream is not modified.
      Parameters:
      v - The byte to write to the stream.
      dest - The position at which to store the byte in the buffer.
    • writeByteSeq

      public void writeByteSeq(byte[] v)
      Writes a byte sequence to the stream.
      Parameters:
      v - The byte sequence to write to the stream. Passing null causes an empty sequence to be written to the stream.
    • writeByteSeq

      public void writeByteSeq(int tag, Optional<byte[]> v)
      Writes an optional byte sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional byte sequence to write to the stream.
    • writeByteSeq

      public void writeByteSeq(int tag, byte[] v)
      Writes an optional byte sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The byte sequence to write to the stream.
    • writeByteBuffer

      public void writeByteBuffer(ByteBuffer v)
      Writes the remaining contents of the byte buffer as a byte sequence to the stream.
      Parameters:
      v - The byte buffer to write to the stream.
    • writeSerializable

      public void writeSerializable(Serializable o)
      Writes a serializable Java object to the stream.
      Parameters:
      o - The serializable object to write.
    • writeSerializable

      public <T extends Serializable> void writeSerializable(int tag, Optional<T> v)
      Writes an optional serializable Java object to the stream.
      Type Parameters:
      T - The serializable class.
      Parameters:
      tag - The optional tag.
      v - The optional serializable object to write.
    • writeSerializable

      public void writeSerializable(int tag, Serializable v)
      Writes an optional serializable Java object to the stream.
      Parameters:
      tag - The optional tag.
      v - The serializable object to write.
    • writeBool

      public void writeBool(boolean v)
      Writes a boolean to the stream.
      Parameters:
      v - The boolean to write to the stream.
    • writeBool

      public void writeBool(int tag, Optional<Boolean> v)
      Writes an optional boolean to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional boolean to write to the stream.
    • writeBool

      public void writeBool(int tag, boolean v)
      Writes an optional boolean to the stream.
      Parameters:
      tag - The optional tag.
      v - The boolean to write to the stream.
    • rewriteBool

      public void rewriteBool(boolean v, int dest)
      Writes a boolean to the stream at the given position. The current position of the stream is not modified.
      Parameters:
      v - The boolean to write to the stream.
      dest - The position at which to store the boolean in the buffer.
    • writeBoolSeq

      public void writeBoolSeq(boolean[] v)
      Writes a boolean sequence to the stream.
      Parameters:
      v - The boolean sequence to write to the stream. Passing null causes an empty sequence to be written to the stream.
    • writeBoolSeq

      public void writeBoolSeq(int tag, Optional<boolean[]> v)
      Writes an optional boolean sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional boolean sequence to write to the stream.
    • writeBoolSeq

      public void writeBoolSeq(int tag, boolean[] v)
      Writes an optional boolean sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The boolean sequence to write to the stream.
    • writeShort

      public void writeShort(short v)
      Writes a short to the stream.
      Parameters:
      v - The short to write to the stream.
    • writeShort

      public void writeShort(int tag, Optional<Short> v)
      Writes an optional short to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional short to write to the stream.
    • writeShort

      public void writeShort(int tag, short v)
      Writes an optional short to the stream.
      Parameters:
      tag - The optional tag.
      v - The short to write to the stream.
    • writeShortSeq

      public void writeShortSeq(short[] v)
      Writes a short sequence to the stream.
      Parameters:
      v - The short sequence to write to the stream. Passing null causes an empty sequence to be written to the stream.
    • writeShortSeq

      public void writeShortSeq(int tag, Optional<short[]> v)
      Writes an optional short sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional short sequence to write to the stream.
    • writeShortSeq

      public void writeShortSeq(int tag, short[] v)
      Writes an optional short sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The short sequence to write to the stream.
    • writeShortBuffer

      public void writeShortBuffer(ShortBuffer v)
      Writes the remaining contents of the short buffer as a short sequence to the stream.
      Parameters:
      v - The short buffer to write to the stream.
    • writeInt

      public void writeInt(int v)
      Writes an int to the stream.
      Parameters:
      v - The int to write to the stream.
    • writeInt

      public void writeInt(int tag, OptionalInt v)
      Writes an optional int to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional int to write to the stream.
    • writeInt

      public void writeInt(int tag, int v)
      Writes an optional int to the stream.
      Parameters:
      tag - The optional tag.
      v - The int to write to the stream.
    • rewriteInt

      public void rewriteInt(int v, int dest)
      Writes an int to the stream at the given position. The current position of the stream is not modified.
      Parameters:
      v - The int to write to the stream.
      dest - The position at which to store the int in the buffer.
    • writeIntSeq

      public void writeIntSeq(int[] v)
      Writes an int sequence to the stream.
      Parameters:
      v - The int sequence to write to the stream. Passing null causes an empty sequence to be written to the stream.
    • writeIntSeq

      public void writeIntSeq(int tag, Optional<int[]> v)
      Writes an optional int sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional int sequence to write to the stream.
    • writeIntSeq

      public void writeIntSeq(int tag, int[] v)
      Writes an optional int sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The int sequence to write to the stream.
    • writeIntBuffer

      public void writeIntBuffer(IntBuffer v)
      Writes the remaining contents of the int buffer as an int sequence to the stream.
      Parameters:
      v - The int buffer to write to the stream.
    • writeLong

      public void writeLong(long v)
      Writes a long to the stream.
      Parameters:
      v - The long to write to the stream.
    • writeLong

      public void writeLong(int tag, OptionalLong v)
      Writes an optional long to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional long to write to the stream.
    • writeLong

      public void writeLong(int tag, long v)
      Writes an optional long to the stream.
      Parameters:
      tag - The optional tag.
      v - The long to write to the stream.
    • writeLongSeq

      public void writeLongSeq(long[] v)
      Writes a long sequence to the stream.
      Parameters:
      v - The long sequence to write to the stream. Passing null causes an empty sequence to be written to the stream.
    • writeLongSeq

      public void writeLongSeq(int tag, Optional<long[]> v)
      Writes an optional long sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional long sequence to write to the stream.
    • writeLongSeq

      public void writeLongSeq(int tag, long[] v)
      Writes an optional long sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The long sequence to write to the stream.
    • writeLongBuffer

      public void writeLongBuffer(LongBuffer v)
      Writes the remaining contents of the long buffer as a long sequence to the stream.
      Parameters:
      v - The long buffer to write to the stream.
    • writeFloat

      public void writeFloat(float v)
      Writes a float to the stream.
      Parameters:
      v - The float to write to the stream.
    • writeFloat

      public void writeFloat(int tag, Optional<Float> v)
      Writes an optional float to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional float to write to the stream.
    • writeFloat

      public void writeFloat(int tag, float v)
      Writes an optional float to the stream.
      Parameters:
      tag - The optional tag.
      v - The float to write to the stream.
    • writeFloatSeq

      public void writeFloatSeq(float[] v)
      Writes a float sequence to the stream.
      Parameters:
      v - The float sequence to write to the stream. Passing null causes an empty sequence to be written to the stream.
    • writeFloatSeq

      public void writeFloatSeq(int tag, Optional<float[]> v)
      Writes an optional float sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional float sequence to write to the stream.
    • writeFloatSeq

      public void writeFloatSeq(int tag, float[] v)
      Writes an optional float sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The float sequence to write to the stream.
    • writeFloatBuffer

      public void writeFloatBuffer(FloatBuffer v)
      Writes the remaining contents of the float buffer as a float sequence to the stream.
      Parameters:
      v - The float buffer to write to the stream.
    • writeDouble

      public void writeDouble(double v)
      Writes a double to the stream.
      Parameters:
      v - The double to write to the stream.
    • writeDouble

      public void writeDouble(int tag, OptionalDouble v)
      Writes an optional double to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional double to write to the stream.
    • writeDouble

      public void writeDouble(int tag, double v)
      Writes an optional double to the stream.
      Parameters:
      tag - The optional tag.
      v - The double to write to the stream.
    • writeDoubleSeq

      public void writeDoubleSeq(double[] v)
      Writes a double sequence to the stream.
      Parameters:
      v - The double sequence to write to the stream. Passing null causes an empty sequence to be written to the stream.
    • writeDoubleSeq

      public void writeDoubleSeq(int tag, Optional<double[]> v)
      Writes an optional double sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional double sequence to write to the stream.
    • writeDoubleSeq

      public void writeDoubleSeq(int tag, double[] v)
      Writes an optional double sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The double sequence to write to the stream.
    • writeDoubleBuffer

      public void writeDoubleBuffer(DoubleBuffer v)
      Writes the remaining contents of the double buffer as a double sequence to the stream.
      Parameters:
      v - The double buffer to write to the stream.
    • writeString

      public void writeString(String v)
      Writes a string to the stream.
      Parameters:
      v - The string to write to the stream. Passing null causes an empty string to be written to the stream.
    • writeString

      public void writeString(int tag, Optional<String> v)
      Writes an optional string to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional string to write to the stream.
    • writeString

      public void writeString(int tag, String v)
      Writes an optional string to the stream.
      Parameters:
      tag - The optional tag.
      v - The string to write to the stream.
    • writeStringSeq

      public void writeStringSeq(String[] v)
      Writes a string sequence to the stream.
      Parameters:
      v - The string sequence to write to the stream. Passing null causes an empty sequence to be written to the stream.
    • writeStringSeq

      public void writeStringSeq(int tag, Optional<String[]> v)
      Writes an optional string sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The optional string sequence to write to the stream.
    • writeStringSeq

      public void writeStringSeq(int tag, String[] v)
      Writes an optional string sequence to the stream.
      Parameters:
      tag - The optional tag.
      v - The string sequence to write to the stream.
    • writeProxy

      public void writeProxy(ObjectPrx v)
      Writes a proxy to the stream.
      Parameters:
      v - The proxy to write.
    • writeProxy

      public <Prx extends ObjectPrx> void writeProxy(int tag, Optional<Prx> v)
      Writes an optional proxy to the stream.
      Type Parameters:
      Prx - The proxy type.
      Parameters:
      tag - The optional tag.
      v - The optional proxy to write to the stream.
    • writeProxy

      public void writeProxy(int tag, ObjectPrx v)
      Writes an optional proxy to the stream.
      Parameters:
      tag - The optional tag.
      v - The proxy to write to the stream.
    • writeEnum

      public void writeEnum(int v, int maxValue)
      Write an enumerated value.
      Parameters:
      v - The enumerator.
      maxValue - The maximum enumerator value in the definition.
    • writeValue

      public void writeValue(Value v)
      Writes a Slice value to the stream.
      Parameters:
      v - The value to write. This method writes the index of an instance; the state of the value is written once writePendingValues() is called.
    • writeException

      public void writeException(UserException v)
      Writes a user exception to the stream.
      Parameters:
      v - The user exception to write.
    • pos

      public int pos()
      Determines the current position in the stream.
      Returns:
      The current position.
    • pos

      public void pos(int n)
      Sets the current position in the stream.
      Parameters:
      n - The new position.
    • size

      public int size()
      Determines the current size of the stream.
      Returns:
      The current size.
    • isEmpty

      public boolean isEmpty()
      Determines whether the stream is empty.
      Returns:
      True if no data has been written yet, false otherwise.
    • expand

      public void expand(int n)
      Expand the stream to accept more data.
      Parameters:
      n - The number of bytes to accommodate in the stream.