Class AbstractInternalDeserializer

java.lang.Object
com.pnfsoftware.jeb.util.serialization.AbstractInternalDeserializer

public abstract class AbstractInternalDeserializer extends Object
Base class for deserializers. Client code should not extend.
  • Field Details

    • in

      protected LEDataInputStream in
      Input stream providing serialized data.
    • nativeTypeIdProvider

      protected ITypeIdProvider nativeTypeIdProvider
      Native type-id provider.
    • customTypeIdProvider

      protected ITypeIdProvider customTypeIdProvider
      Optional caller-provided type-id provider.
    • classloaders

      protected List<ClassLoader> classloaders
      Class loaders used to resolve serialized types.
    • objenesis

      protected org.objenesis.ObjenesisStd objenesis
      Object instantiator used for deserialization.
    • cancelled

      protected boolean cancelled
      True if deserialization was cancelled.
    • constructorMap

      protected Map<Class<?>,Object> constructorMap
      Cache of constructor-related objects by class.
    • mootObject

      protected Object mootObject
      Placeholder object used for unresolved references.
    • objmap

      protected Map<Integer,Object> objmap
      Deserialized objects by serialized object id.
    • objIdPostgraphDone

      protected Set<Integer> objIdPostgraphDone
      Object ids whose post-graph initialization completed.
    • deferredObjects

      protected List<com.pnfsoftware.jeb.util.serialization.IPreObject> deferredObjects
      Objects whose construction is deferred until the object map is available.
    • customMethods

      protected static Map<Class<?>,com.pnfsoftware.jeb.util.serialization.AbstractInternalDeserializer.CustomMethods> customMethods
      Cached custom serialization methods by class.
    • expectedObjectCount

      protected int expectedObjectCount
      Expected number of objects to deserialize, if known.
    • progressCallbacks

      protected List<IProgressCallback> progressCallbacks
      Progress callbacks to notify during deserialization.
    • objectCreatedHookMap

      protected MultiMap<Class<?>,IDeserializationEventHandler> objectCreatedHookMap
      Object-created hooks by target class.
  • Constructor Details

    • AbstractInternalDeserializer

      protected AbstractInternalDeserializer(ITypeIdProvider customTypeIdProvider, List<ClassLoader> classloaders, LEDataInputStream in)
      Create an internal deserializer.
      Parameters:
      customTypeIdProvider - optional custom type-id provider
      classloaders - class loaders used to resolve serialized types
      in - serialized data input stream
  • Method Details

    • getObjectCount

      public int getObjectCount()
    • getObjects

      public Collection<Object> getObjects()
    • getStream

      public InputStream getStream()
    • deserializeInternal

      public Object deserializeInternal() throws IOException
      Throws:
      IOException
    • close

      public void close() throws IOException
      Close the underlying input stream.
      Throws:
      IOException - on stream close error
    • read

      public Object read() throws IOException
      Throws:
      IOException
    • read

      public Object read(Object object, Class<?> c) throws IOException
      Read one object, optionally into an existing object or as a target class.
      Parameters:
      object - optional existing object to populate
      c - optional target class
      Returns:
      deserialized object
      Throws:
      IOException - on deserialization error
    • readInternal

      protected abstract Object readInternal(Object object, Class<?> c) throws IOException
      Read one object from the serialized stream.
      Parameters:
      object - optional existing object to populate
      c - optional target class
      Returns:
      deserialized object
      Throws:
      IOException - on deserialization error
    • registerObject

      protected void registerObject(boolean isLeafObject, int objectId, Object o)
      Register a deserialized object by id.
      Parameters:
      isLeafObject - true if the object should be stored in the object map
      objectId - serialized object id
      o - deserialized object
    • loadClass

      protected Class<?> loadClass(String typeName) throws ClassNotFoundException
      Resolve a serialized class name.
      Parameters:
      typeName - fully-qualified type name
      Returns:
      resolved class
      Throws:
      ClassNotFoundException - if the class cannot be resolved
    • restoreFieldValue

      protected void restoreFieldValue(Object o, Class<?> targetClass, int fieldId, Object fieldObject) throws SerializationException
      Restore one serialized field value on an object.
      Parameters:
      o - target object
      targetClass - optional class declaring the field
      fieldId - serialized field id
      fieldObject - field value
      Throws:
      SerializationException - on reflection or assignment error
    • getCustomMethods

      protected com.pnfsoftware.jeb.util.serialization.AbstractInternalDeserializer.CustomMethods getCustomMethods(Object o, Class<?> targetClass) throws SerializationException
      Retrieve serialization custom methods for a target object or class.
      Parameters:
      o - target object
      targetClass - optional target class
      Returns:
      custom method descriptors
      Throws:
      SerializationException - if a custom method has an invalid prototype
    • resolveDeferredObjects

      protected void resolveDeferredObjects()
      Resolve deferred objects using the current object map.
    • setExpectedObjectCount

      public void setExpectedObjectCount(int count)
    • addProgressCallback

      public void addProgressCallback(IProgressCallback callback)
    • removeProgressCallback

      public void removeProgressCallback(IProgressCallback callback)
    • notifyProgressCallbacks

      protected void notifyProgressCallbacks()
      Notify registered progress callbacks.
    • addObjectCreatedHook

      public void addObjectCreatedHook(Class<?> c, IDeserializationEventHandler handler)
    • removeObjectCreatedHook

      public void removeObjectCreatedHook(Class<?> c, IDeserializationEventHandler handler)
    • notifyDeserializationEvent

      protected void notifyDeserializationEvent(int type, Class<?> c, Object o)
      Notify deserialization event handlers.
      Parameters:
      type - event type: 1= object created (post creation)
      c - object class
      o - deserialized object
    • logObjectMap

      protected void logObjectMap()
      Log the current object id map for diagnostics.
    • restoreFields

      void restoreFields(Object o, Class<?> targetClass) throws IOException
      Restore serialized fields on an object.
      Parameters:
      o - target object
      targetClass - optional target class
      Throws:
      IOException - on deserialization error