Class ObjectSerializerImpl

java.lang.Object
org.jppf.utils.ObjectSerializerImpl
All Implemented Interfaces:
ObjectSerializer

public class ObjectSerializerImpl extends Object implements ObjectSerializer
Instances of this class are used to serialize or deserialize objects to or from an array of bytes.
A specific use of this class is that it can be loaded by a new classloader, making the execution transparent to any change in the client code.
Author:
Laurent Cohen
  • Constructor Details

    • ObjectSerializerImpl

      public ObjectSerializerImpl()
      The default constructor must be public to allow for instantiation through Java reflection.
  • Method Details

    • serialize

      public JPPFBuffer serialize(Object o) throws Exception
      Serialize an object into an array of bytes.
      Specified by:
      serialize in interface ObjectSerializer
      Parameters:
      o - the object to Serialize.
      Returns:
      a JPPFBuffer instance holding the serialized object.
      Throws:
      Exception - if the object can't be serialized.
    • serialize

      public JPPFBuffer serialize(Object o, boolean noCopy) throws Exception
      Serialize an object into an array of bytes.
      Specified by:
      serialize in interface ObjectSerializer
      Parameters:
      o - the object to Serialize.
      noCopy - avoid copying intermediate buffers.
      Returns:
      a JPPFBuffer instance holding the serialized object.
      Throws:
      Exception - if the object can't be serialized.
    • serialize

      public void serialize(Object o, OutputStream os) throws Exception
      Serialize an object into an output stream.
      Specified by:
      serialize in interface ObjectSerializer
      Parameters:
      o - the object to Serialize.
      os - the output stream to serialize to.
      Throws:
      Exception - if the object can't be serialized.
    • deserialize

      public Object deserialize(JPPFBuffer buf) throws Exception
      Read an object from an array of bytes.
      Specified by:
      deserialize in interface ObjectSerializer
      Parameters:
      buf - buffer holding the array of bytes to deserialize from.
      Returns:
      the object that was deserialized from the array of bytes.
      Throws:
      Exception - if the ObjectInputStream used for deserialization raises an error.
    • deserialize

      public Object deserialize(byte[] bytes) throws Exception
      Read an object from an array of bytes.
      Specified by:
      deserialize in interface ObjectSerializer
      Parameters:
      bytes - buffer holding the array of bytes to deserialize from.
      Returns:
      the object that was deserialized from the array of bytes.
      Throws:
      Exception - if the ObjectInputStream used for deserialization raises an error.
    • deserialize

      public Object deserialize(byte[] bytes, int offset, int length) throws Exception
      Read an object from an array of bytes.
      Specified by:
      deserialize in interface ObjectSerializer
      Parameters:
      bytes - buffer holding the array of bytes to deserialize from.
      offset - position at which to start reading the bytes from.
      length - the number of bytes to read.
      Returns:
      the object that was deserialized from the array of bytes.
      Throws:
      Exception - if the ObjectInputStream used for deserialization raises an error.
    • deserialize

      public Object deserialize(InputStream is) throws Exception
      Description copied from interface: ObjectSerializer
      Read an object from an input stream.
      Specified by:
      deserialize in interface ObjectSerializer
      Parameters:
      is - the input stream to deserialize from.
      Returns:
      the object that was deserialized from the array of bytes.
      Throws:
      Exception - if the ObjectInputStream used for deserialization raises an error.
    • deserialize

      public Object deserialize(InputStream is, boolean closeStream) throws Exception
      Read an object from an input stream.
      Parameters:
      is - the input stream to deserialize from.
      closeStream - true to close the stream, false otherwise.
      Returns:
      the object that was deserialized from the array of bytes.
      Throws:
      Exception - if the ObjectInputStream used for deserialization raises an error.