Class AnnotatedObjectInputStream

java.lang.Object
java.io.InputStream
java.io.ObjectInputStream
com.gigaspaces.internal.io.AnnotatedObjectInputStream
All Implemented Interfaces:
Closeable, DataInput, ObjectInput, ObjectStreamConstants, AutoCloseable
Direct Known Subclasses:
MarshalInputStream

public class AnnotatedObjectInputStream extends ObjectInputStream
An extension of ObjectInputStream that implements the dynamic class loading semantics of RMI argument and result unmarshalling (using RMIClassLoader). A AnnotatedObjectInputStream is intended to read data written by a corresponding AnnotatedObjectOutputStream.

AnnotatedObjectInputStream implements the input side of the dynamic class loading semantics by overriding resolveClass and resolveProxyClass to resolve class descriptors in the stream using ClassLoading.loadClass and ClassLoading.loadProxyClass (which, in turn, use RMIClassLoader.loadClass and RMIClassLoader.loadProxyClass), optionally with CodeBase annotation strings written by a AnnotatedObjectOutputStream.

AnnotatedObjectInputStream reads class annotations from its own stream; a subclass can override the readAnnotation method to read the class annotations from a different location.

A AnnotatedObjectInputStream is not guaranteed to be safe for concurrent use by multiple threads.

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

    • AnnotatedObjectInputStream

      public AnnotatedObjectInputStream(InputStream in) throws IOException
      Creates a new AnnotatedObjectInputStream that reads marshalled data from the specified underlying InputStream.

      This constructor passes in to the superclass constructor that has an InputStream parameter.

      defaultLoader will be passed as the defaultLoader argument to ClassLoading.loadClass and ClassLoading.loadProxyClass whenever those methods are invoked by resolveClass and resolveProxyClass.

      If verifyCodebaseIntegrity is true, then the created stream will verify that all codebase annotation URLs that are used to load classes resolved by the stream provide content integrity, and whenever Security.verifyCodebaseIntegrity is invoked to enforce that verification, verifierLoader will be passed as the loader argument. See ClassLoading.loadClass and ClassLoading.loadProxyClass for details of how codebase integrity verification is performed.

      context will be used as the return value of the created stream's getObjectStreamContext method.

      Parameters:
      in - the input stream to read marshalled data from
      defaultLoader - the class loader value (possibly null) to pass as the defaultLoader argument to ClassLoading methods
      context - the collection of context information objects to be returned by this stream's getObjectStreamContext method
      Throws:
      IOException - if the superclass's constructor throws an IOException
      SecurityException - if the superclass's constructor throws a SecurityException
      NullPointerException - if in or context is null
  • Method Details

    • resolveClass

      protected Class resolveClass(ObjectStreamClass classDesc, boolean readAnnotation, String codebase) throws IOException, ClassNotFoundException
      Resolves the appropriate Class object for the stream class descriptor classDesc.

      AnnotatedObjectInputStream implements this method as follows:

      Invokes this stream's readAnnotation method to read the annotation string value (possibly null) for the class descriptor. If readAnnotation throws an exception, then this method throws that exception. Otherwise, a codebase value is chosen as follows: if the useCodebaseAnnotations method has been invoked on this stream, then the codebase value chosen is the value that was returned by readAnnotation; otherwise, the codebase value chosen is null.

      This method then invokes ClassLoading.loadClass with the chosen codebase value as the first argument, the name of the class described by classDesc as the second argument, and the defaultLoader, verifyCodebaseIntegrity, and verifierLoader values that were passed to this stream's constructor as the third, fourth, and fifth arguments. If ClassLoading.loadClass throws a ClassNotFoundException and the name of the class described by classDesc equals the Java(TM) programming language keyword for a primitive type or void, then this method returns the Class corresponding to that primitive type or void (Integer.TYPE for int, Void.TYPE for void, and so forth). Otherwise, if ClassLoading.loadClass throws an exception, this method throws that exception, and if it returns normally, this method returns the Class returned by ClassLoading.loadClass.

      Parameters:
      classDesc - the stream class descriptor to resolve
      Returns:
      the resolved class
      Throws:
      IOException - if readAnnotation throws an IOException, or if ClassLoading.loadClass throws a MalformedURLException
      ClassNotFoundException - if readAnnotation or ClassLoading.loadClass throws a ClassNotFoundException
      NullPointerException - if classDesc is null
    • resolveClass

      protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException
      Overrides:
      resolveClass in class ObjectInputStream
      Throws:
      IOException
      ClassNotFoundException
    • readAnnotation

      protected String readAnnotation(ObjectStreamClass desc) throws IOException, ClassNotFoundException
      Reads and returns a class annotation string value (possibly null) that was written by a corresponding AnnotatedObjectOutputStream implementation.

      AnnotatedObjectInputStream implements this method to just read the annotation value from this stream using readUnshared, and if readUnshared returns a non-null value that is not a String, an InvalidObjectException is thrown.

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

      Returns:
      the class annotation string value read (possibly null)
      Throws:
      IOException - if an I/O exception occurs reading the annotation
      ClassNotFoundException - if a ClassNotFoundException occurs reading the annotation