Package com.zeroc.Ice

Class InputStream

java.lang.Object
com.zeroc.Ice.InputStream

public class InputStream extends Object
Interface to read sequence of bytes encoded using the Ice encoding and recreate the corresponding Slice types.
See Also:
  • Constructor Details

    • InputStream

      public InputStream()
      Constructing an InputStream without providing a communicator means the stream will use the default encoding version. A communicator is required in order to unmarshal proxies. You can supply a communicator later by calling initialize().
    • InputStream

      public InputStream(byte[] data)
      Constructing an InputStream without providing a communicator means the stream will use the default encoding version. A communicator is required in order to unmarshal proxies. You can supply a communicator later by calling initialize().
      Parameters:
      data - The byte array containing encoded Slice types.
    • InputStream

      public InputStream(ByteBuffer buf)
      Constructing an InputStream without providing a communicator means the stream will use the default encoding version. A communicator is required in order to unmarshal proxies. You can supply a communicator later by calling initialize().
      Parameters:
      buf - The byte buffer containing encoded Slice types.
    • InputStream

      public InputStream(com.zeroc.IceInternal.Buffer buf)
    • InputStream

      public InputStream(com.zeroc.IceInternal.Buffer buf, boolean adopt)
    • InputStream

      public InputStream(Communicator communicator)
      This constructor uses the communicator's default encoding version.
      Parameters:
      communicator - The communicator to use when initializing the stream.
    • InputStream

      public InputStream(Communicator communicator, byte[] data)
      This constructor uses the communicator's default encoding version.
      Parameters:
      communicator - The communicator to use when initializing the stream.
      data - The byte array containing encoded Slice types.
    • InputStream

      public InputStream(Communicator communicator, ByteBuffer buf)
      This constructor uses the communicator's default encoding version.
      Parameters:
      communicator - The communicator to use when initializing the stream.
      buf - The byte buffer containing encoded Slice types.
    • InputStream

      public InputStream(Communicator communicator, com.zeroc.IceInternal.Buffer buf)
    • InputStream

      public InputStream(Communicator communicator, com.zeroc.IceInternal.Buffer buf, boolean adopt)
    • InputStream

      public InputStream(EncodingVersion encoding)
      This constructor uses the given encoding version.
      Parameters:
      encoding - The encoding version to use when extracting data.
    • InputStream

      public InputStream(EncodingVersion encoding, byte[] data)
      This constructor uses the given encoding version.
      Parameters:
      encoding - The encoding version to use when extracting data.
      data - The byte array containing encoded Slice types.
    • InputStream

      public InputStream(EncodingVersion encoding, ByteBuffer buf)
      This constructor uses the given encoding version.
      Parameters:
      encoding - The encoding version to use when extracting data.
      buf - The byte buffer containing encoded Slice types.
    • InputStream

      public InputStream(EncodingVersion encoding, com.zeroc.IceInternal.Buffer buf)
    • InputStream

      public InputStream(EncodingVersion encoding, com.zeroc.IceInternal.Buffer buf, boolean adopt)
    • InputStream

      public InputStream(Communicator communicator, EncodingVersion encoding)
      This constructor uses the given communicator and encoding version.
      Parameters:
      communicator - The communicator to use when initializing the stream.
      encoding - The desired encoding version.
    • InputStream

      public InputStream(Communicator communicator, EncodingVersion encoding, byte[] data)
      This constructor uses the given communicator and encoding version.
      Parameters:
      communicator - The communicator to use when initializing the stream.
      encoding - The desired encoding version.
      data - The byte array containing encoded Slice types.
    • InputStream

      public InputStream(Communicator communicator, EncodingVersion encoding, ByteBuffer buf)
      This constructor uses the given communicator and encoding version.
      Parameters:
      communicator - The communicator to use when initializing the stream.
      encoding - The desired encoding version.
      buf - The byte buffer containing encoded Slice types.
    • InputStream

      public InputStream(Communicator communicator, EncodingVersion encoding, com.zeroc.IceInternal.Buffer buf)
    • InputStream

      public InputStream(Communicator communicator, EncodingVersion encoding, com.zeroc.IceInternal.Buffer buf, boolean adopt)
    • InputStream

      public InputStream(com.zeroc.IceInternal.Instance instance, EncodingVersion encoding)
    • InputStream

      public InputStream(com.zeroc.IceInternal.Instance instance, EncodingVersion encoding, boolean direct)
    • InputStream

      public InputStream(com.zeroc.IceInternal.Instance instance, EncodingVersion encoding, byte[] data)
    • InputStream

      public InputStream(com.zeroc.IceInternal.Instance instance, EncodingVersion encoding, ByteBuffer data)
    • InputStream

      public InputStream(com.zeroc.IceInternal.Instance instance, EncodingVersion encoding, com.zeroc.IceInternal.Buffer buf, boolean adopt)
  • Method Details

    • initialize

      public void initialize(Communicator communicator)
      Initializes the stream to use the communicator's default encoding version.
      Parameters:
      communicator - The communicator to use when initializing the stream.
    • initialize

      public void initialize(Communicator communicator, EncodingVersion encoding)
      Initializes the stream to use the given communicator and encoding version.
      Parameters:
      communicator - The communicator to use when initializing the stream.
      encoding - The desired encoding version.
    • reset

      public void reset()
      Resets this 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.
    • setValueFactoryManager

      public void setValueFactoryManager(ValueFactoryManager vfm)
      Sets the value factory manager to use when unmarshaling value instances. If the stream was initialized with a communicator, the communicator's value factory manager will be used by default.
      Parameters:
      vfm - The value factory manager.
    • setLogger

      public void setLogger(Logger logger)
      Sets the logger to use when logging trace messages. If the stream was initialized with a communicator, the communicator's logger will be used by default.
      Parameters:
      logger - The logger to use for logging trace messages.
    • setCompactIdResolver

      public void setCompactIdResolver(IntFunction<String> r)
      Sets the compact ID resolver to use when unmarshaling value and exception instances. If the stream was initialized with a communicator, the communicator's resolver will be used by default.
      Parameters:
      r - The compact ID resolver.
    • setClassResolver

      public void setClassResolver(Function<String,Class<?>> r)
      Sets the class resolver, which the stream will use when attempting to unmarshal a value or exception. If the stream was initialized with a communicator, the communicator's resolver will be used by default.
      Parameters:
      r - The class resolver.
    • setSliceValues

      public void setSliceValues(boolean b)
      Determines the behavior of the stream when extracting instances of Slice classes. An instance is "sliced" when a factory cannot be found for a Slice type ID. The stream's default behavior is to slice instances.
      Parameters:
      b - If true (the default), slicing is enabled; if false, slicing is disabled. If slicing is disabled and the stream encounters a Slice type ID during decoding for which no value factory is installed, it raises NoValueFactoryException.
    • setTraceSlicing

      public void setTraceSlicing(boolean b)
      Determines whether the stream logs messages about slicing instances of Slice values.
      Parameters:
      b - True to enable logging, false to disable logging.
    • getClosure

      public Object getClosure()
      Retrieves the closure object associated with this stream.
      Returns:
      The closure object.
    • setClosure

      public Object setClosure(Object p)
      Associates a closure object with this stream.
      Parameters:
      p - The new closure object.
      Returns:
      The previous closure object, or null.
    • instance

      public com.zeroc.IceInternal.Instance instance()
    • swap

      public void swap(InputStream 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.
    • getBuffer

      public com.zeroc.IceInternal.Buffer getBuffer()
    • startValue

      public void startValue()
      Marks the start of a class instance.
    • endValue

      public SlicedData endValue(boolean preserve)
      Marks the end of a class instance.
      Parameters:
      preserve - Pass true and the stream will preserve the unknown slices of the instance, or false to discard the unknown slices.
      Returns:
      An object that encapsulates the unknown slice data.
    • startException

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

      public SlicedData endException(boolean preserve)
      Marks the end of a user exception.
      Parameters:
      preserve - Pass true and the stream will preserve the unknown slices of the exception, or false to discard the unknown slices.
      Returns:
      An object that encapsulates the unknown slice data.
    • startEncapsulation

      public EncodingVersion startEncapsulation()
      Reads the start of an encapsulation.
      Returns:
      The encoding version used by the encapsulation.
    • endEncapsulation

      public void endEncapsulation()
      Ends the current encapsulation.
    • skipEmptyEncapsulation

      public EncodingVersion skipEmptyEncapsulation()
      Skips an empty encapsulation.
      Returns:
      The encapsulation's encoding version.
    • readEncapsulation

      public byte[] readEncapsulation(EncodingVersion encoding)
      Returns a blob of bytes representing an encapsulation. The encapsulation's encoding version is returned in the argument.
      Parameters:
      encoding - The encapsulation's encoding version.
      Returns:
      The encoded encapsulation.
    • getEncoding

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

      public int getEncapsulationSize()
      Determines the size of the current encapsulation, excluding the encapsulation header.
      Returns:
      The size of the encapsulated data.
    • skipEncapsulation

      public EncodingVersion skipEncapsulation()
      Skips over an encapsulation.
      Returns:
      The encoding version of the skipped encapsulation.
    • startSlice

      public String startSlice()
      Reads the start of a value or exception slice.
      Returns:
      The Slice type ID for this slice.
    • endSlice

      public void endSlice()
      Indicates that the end of a value or exception slice has been reached.
    • skipSlice

      public void skipSlice()
      Skips over a value or exception slice.
    • readPendingValues

      public void readPendingValues()
      Indicates that unmarshaling is complete, except for any class instances. The application must call this method only if the stream actually contains class instances. Calling readPendingValues triggers the calls to consumers provided with readValue(java.util.function.Consumer<T>, java.lang.Class<T>) to inform the application that unmarshaling of an instance is complete.
    • readSize

      public int readSize()
      Extracts a size from the stream.
      Returns:
      The extracted size.
    • readAndCheckSeqSize

      public int readAndCheckSeqSize(int minSize)
      Reads and validates a sequence size.
      Parameters:
      minSize - The minimum size required by the sequence type.
      Returns:
      The extracted size.
    • readBlob

      public byte[] readBlob(int sz)
      Reads a blob of bytes from the stream.
      Parameters:
      sz - The number of bytes to read.
      Returns:
      The requested bytes as a byte array.
    • readOptional

      public boolean readOptional(int tag, OptionalFormat expectedFormat)
      Determine if an optional value is available for reading.
      Parameters:
      tag - The tag associated with the value.
      expectedFormat - The optional format for the value.
      Returns:
      True if the value is present, false otherwise.
    • readByte

      public byte readByte()
      Extracts a byte value from the stream.
      Returns:
      The extracted byte.
    • readByte

      public Optional<Byte> readByte(int tag)
      Extracts an optional byte value from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readByteSeq

      public byte[] readByteSeq()
      Extracts a sequence of byte values from the stream.
      Returns:
      The extracted byte sequence.
    • readByteSeq

      public Optional<byte[]> readByteSeq(int tag)
      Extracts an optional byte sequence from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readByteBuffer

      public ByteBuffer readByteBuffer()
      Returns a byte buffer representing a sequence of bytes. This method does not copy the data.
      Returns:
      A byte buffer "slice" of the internal buffer.
    • readSerializable

      public <T extends Serializable> T readSerializable(Class<T> cl)
      Extracts a serializable Java object from the stream.
      Type Parameters:
      T - The serializable type.
      Parameters:
      cl - The class for the serializable type.
      Returns:
      The deserialized Java object.
    • readSerializable

      public <T extends Serializable> Optional<T> readSerializable(int tag, Class<T> cl)
      Extracts a optional serializable Java object from the stream.
      Type Parameters:
      T - The serializable type.
      Parameters:
      tag - The numeric tag associated with the value.
      cl - The class for the serializable type.
      Returns:
      The optional value (if any).
    • readBool

      public boolean readBool()
      Extracts a boolean value from the stream.
      Returns:
      The extracted boolean.
    • readBool

      public Optional<Boolean> readBool(int tag)
      Extracts an optional boolean value from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readBoolSeq

      public boolean[] readBoolSeq()
      Extracts a sequence of boolean values from the stream.
      Returns:
      The extracted boolean sequence.
    • readBoolSeq

      public Optional<boolean[]> readBoolSeq(int tag)
      Extracts an optional boolean sequence from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readShort

      public short readShort()
      Extracts a short value from the stream.
      Returns:
      The extracted short.
    • readShort

      public Optional<Short> readShort(int tag)
      Extracts an optional short value from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readShortSeq

      public short[] readShortSeq()
      Extracts a sequence of short values from the stream.
      Returns:
      The extracted short sequence.
    • readShortSeq

      public Optional<short[]> readShortSeq(int tag)
      Extracts an optional short sequence from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readShortBuffer

      public ShortBuffer readShortBuffer()
      Returns a short buffer representing a sequence of shorts. This method does not copy the data.
      Returns:
      A short buffer "slice" of the internal buffer.
    • readInt

      public int readInt()
      Extracts an int value from the stream.
      Returns:
      The extracted int.
    • readInt

      public OptionalInt readInt(int tag)
      Extracts an optional int value from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readIntSeq

      public int[] readIntSeq()
      Extracts a sequence of int values from the stream.
      Returns:
      The extracted int sequence.
    • readIntSeq

      public Optional<int[]> readIntSeq(int tag)
      Extracts an optional int sequence from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readIntBuffer

      public IntBuffer readIntBuffer()
      Returns an int buffer representing a sequence of ints. This method does not copy the data.
      Returns:
      An int buffer "slice" of the internal buffer.
    • readLong

      public long readLong()
      Extracts a long value from the stream.
      Returns:
      The extracted long.
    • readLong

      public OptionalLong readLong(int tag)
      Extracts an optional long value from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readLongSeq

      public long[] readLongSeq()
      Extracts a sequence of long values from the stream.
      Returns:
      The extracted long sequence.
    • readLongSeq

      public Optional<long[]> readLongSeq(int tag)
      Extracts an optional long sequence from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readLongBuffer

      public LongBuffer readLongBuffer()
      Returns a long buffer representing a sequence of longs. This method does not copy the data.
      Returns:
      A long buffer "slice" of the internal buffer.
    • readFloat

      public float readFloat()
      Extracts a float value from the stream.
      Returns:
      The extracted float.
    • readFloat

      public Optional<Float> readFloat(int tag)
      Extracts an optional float value from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readFloatSeq

      public float[] readFloatSeq()
      Extracts a sequence of float values from the stream.
      Returns:
      The extracted float sequence.
    • readFloatSeq

      public Optional<float[]> readFloatSeq(int tag)
      Extracts an optional float sequence from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readFloatBuffer

      public FloatBuffer readFloatBuffer()
      Returns a float buffer representing a sequence of floats. This method does not copy the data.
      Returns:
      A float buffer "slice" of the internal buffer.
    • readDouble

      public double readDouble()
      Extracts a double value from the stream.
      Returns:
      The extracted double.
    • readDouble

      public OptionalDouble readDouble(int tag)
      Extracts an optional double value from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readDoubleSeq

      public double[] readDoubleSeq()
      Extracts a sequence of double values from the stream.
      Returns:
      The extracted double sequence.
    • readDoubleSeq

      public Optional<double[]> readDoubleSeq(int tag)
      Extracts an optional double sequence from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readDoubleBuffer

      public DoubleBuffer readDoubleBuffer()
      Returns a double buffer representing a sequence of doubles. This method does not copy the data.
      Returns:
      A double buffer "slice" of the internal buffer.
    • readString

      public String readString()
      Extracts a string from the stream.
      Returns:
      The extracted string.
    • readString

      public Optional<String> readString(int tag)
      Extracts an optional string value from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readStringSeq

      public String[] readStringSeq()
      Extracts a sequence of string values from the stream.
      Returns:
      The extracted string sequence.
    • readStringSeq

      public Optional<String[]> readStringSeq(int tag)
      Extracts an optional string sequence from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readProxy

      public ObjectPrx readProxy()
      Extracts a proxy from the stream. The stream must have been initialized with a communicator.
      Returns:
      The extracted proxy.
    • readProxy

      public <T extends ObjectPrx> T readProxy(Function<ObjectPrx,T> cast)
    • readProxy

      public Optional<ObjectPrx> readProxy(int tag)
      Extracts an optional proxy from the stream. The stream must have been initialized with a communicator.
      Parameters:
      tag - The numeric tag associated with the value.
      Returns:
      The optional value (if any).
    • readProxy

      public <T extends ObjectPrx> Optional<T> readProxy(int tag, Function<ObjectPrx,T> cast)
      Extracts an optional proxy from the stream. The stream must have been initialized with a communicator.
      Type Parameters:
      T - The proxy type.
      Parameters:
      tag - The numeric tag associated with the value.
      cast - The uncheckedCast function to call on the unmarshaled proxy to obtain the correct proxy type.
      Returns:
      The optional value (if any).
    • readEnum

      public int readEnum(int maxValue)
      Read an enumerated value.
      Parameters:
      maxValue - The maximum enumerator value in the definition.
      Returns:
      The enumerator.
    • readValue

      public <T extends Value> void readValue(Consumer<T> cb, Class<T> cls)
      Extracts a Slice value from the stream.
      Type Parameters:
      T - The value type.
      Parameters:
      cb - The consumer to notify when the extracted instance is available. The stream extracts Slice values in stages. The Ice run time calls accept on the consumer when the corresponding instance has been fully unmarshaled.
      cls - The type of the Ice.Value to unmarshal.
    • readValue

      public void readValue(Consumer<Value> cb)
      Extracts a Slice value from the stream.
      Parameters:
      cb - The consumer to notify when the extracted instance is available. The stream extracts Slice values in stages. The Ice run time calls accept on the consumer when the corresponding instance has been fully unmarshaled.
    • readValue

      public <T extends Value> void readValue(int tag, Consumer<Optional<T>> cb, Class<T> cls)
      Extracts an optional Slice value from the stream.
      Type Parameters:
      T - The value type.
      Parameters:
      tag - The numeric tag associated with the value.
      cb - The consumer to notify when the extracted instance is available. The stream extracts Slice values in stages. The Ice run time calls accept on the consumer when the corresponding instance has been fully unmarshaled.
      cls - The type of the Ice.Value to unmarshal.
    • readValue

      public void readValue(int tag, Consumer<Optional<Value>> cb)
      Extracts an optional Slice value from the stream.
      Parameters:
      tag - The numeric tag associated with the value.
      cb - The consumer to notify when the extracted instance is available. The stream extracts Slice values in stages. The Ice run time calls accept on the consumer when the corresponding instance has been fully unmarshaled.
    • throwException

      public void throwException() throws UserException
      Extracts a user exception from the stream and throws it.
      Throws:
      UserException - The user exception that was unmarshaled.
    • throwException

      public void throwException(UserExceptionFactory factory) throws UserException
      Extracts a user exception from the stream and throws it. The caller can supply a factory to instantiate exception instances.
      Parameters:
      factory - The user exception factory, or null to use the stream's default behavior.
      Throws:
      UserException - The user exception that was unmarshaled.
    • skip

      public void skip(int size)
      Skip the given number of bytes.
      Parameters:
      size - The number of bytes to skip.
    • skipSize

      public void skipSize()
      Skip over a size value.
    • 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 the internal buffer has no data, false otherwise.