Class MarshalOutputStream

All Implemented Interfaces:
Closeable, DataOutput, Flushable, ObjectOutput, ObjectStreamConstants, AutoCloseable

public class MarshalOutputStream extends AnnotatedObjectOutputStream
An extension of ObjectOutputStream that implements the dynamic class loading semantics of RMI argument and result marshalling (using RMIClassLoader). A MarshalOutputStream writes data that is intended to be written by a corresponding MarshalInputStream.

MarshalOutputStream implements the output side of the dynamic class loading semantics by overriding annotateClass and annotateProxyClass to annotate class descriptors in the stream with codebase strings obtained using RMIClassLoader.getClassAnnotation.

MarshalOutputStream writes class annotations to its own stream; a subclass may override the writeAnnotation method to write the class annotations to a different location.

MarshalOutputStream does not modify the stream protocol version of its instances' superclass state (see ObjectOutputStream.useProtocolVersion).

Since:
5.0
Author:
Igor Goldenberg, anna
  • Constructor Details

    • MarshalOutputStream

      public MarshalOutputStream(OutputStream out) throws IOException
      Throws:
      IOException
    • MarshalOutputStream

      public MarshalOutputStream(OutputStream out, boolean optimize) throws IOException
      Creates a new MarshalOutputStream that writes marshalled data to the specified underlying OutputStream.

      This constructor passes out to the superclass constructor that has an OutputStream parameter.

      Parameters:
      out - the output stream to write marshalled data to
      optimize - whether to activate the class description optimization during serialization.
      Throws:
      IOException - if the superclass's constructor throws an IOException
      SecurityException - if the superclass's constructor throws a SecurityException
    • MarshalOutputStream

      public MarshalOutputStream(OutputStream out, MarshalOutputStream base) throws IOException
      Throws:
      IOException
  • Method Details

    • writeRepetitiveObject

      public void writeRepetitiveObject(Object obj) throws IOException
      Writes a repetitive object. If this is the first time this object is written, it is assigned a code which is written along the object. The next time the object is written using this method, only its code is written. NOTE: Objects written using this method are cached and are NEVER cleaned up. If the object you are writing is using a PU resource it will not be released when the PU is terminated, and will cause a leak.
      Throws:
      IOException
    • writeSmartExternalizable

      public void writeSmartExternalizable(SmartExternalizable obj) throws IOException
      Throws:
      IOException
    • writeAnnotation

      protected void writeAnnotation(Class cl) throws IOException
      First checks that this class wasn't written already, if it does do nothing.

      Else invokes RMIClassLoader.getClassAnnotation with cl to get the appropriate class annotation string value (possibly null) and then writes a class annotation string value (possibly null) to be read by a corresponding MarshalInputStream implementation.

      MarshalOutputStream implements this method to just write the annotation value to this stream using writeUnshared.

      A subclass can override this method to write the annotation to a different location.

      Overrides:
      writeAnnotation in class AnnotatedObjectOutputStream
      Parameters:
      cl - the class annotation string value (possibly null) to write
      Throws:
      IOException - if I/O exception occurs writing the annotation
    • writeClassDescriptor

      protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException
      Overrides the original implementation, tries to save sending class descriptor, first checks if the class was already sent. If it does send only the class index otherwise send the class descriptor also.
      Overrides:
      writeClassDescriptor in class ObjectOutputStream
      Parameters:
      desc - class descriptor to write to the stream.
      Throws:
      IOException - If an I/O error has occurred.
    • writeStreamHeader

      protected void writeStreamHeader() throws IOException
      Overrides:
      writeStreamHeader in class ObjectOutputStream
      Throws:
      IOException
    • closeContext

      public void closeContext()
    • resetContext

      public void resetContext()