Class AbstractSerializer

  • Direct Known Subclasses:
    BinarySerializer, XStreamSerializer

    public abstract class AbstractSerializer
    extends java.lang.Object
    This is the common superclass for all Serializer casses in PatternTesting. This class was introduced to be able to abstract from the used XStream library in the log package. This allows us to declare the xstream library as "optional" in the POM file.
    Since:
    1.4 (30.11.2013)
    Author:
    oliver
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract java.io.ObjectInputStream createObjectInputStream​(java.io.InputStream in)
      Creates the ObjectInputStream that deserializes a stream of objects from an InputStream.
      abstract java.io.ObjectOutputStream createObjectOutputStream​(java.io.OutputStream out)
      Creates the ObjectOutputStream that serializees a stream of objects to the OutputStream.
      static AbstractSerializer getInstance()
      This static method returns an instance of the default serializer.
      java.lang.Object load​(java.io.File file)
      Loads a single ojbect from the given file.
      java.lang.Object load​(java.io.InputStream in)
      Loads a single ojbect from the given stream.
      void save​(java.lang.Object object, java.io.File file)
      Saves a single object to the given file.
      void save​(java.lang.Object object, java.io.OutputStream out)
      Saves a single object to the given stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractSerializer

        public AbstractSerializer()
    • Method Detail

      • getInstance

        public static AbstractSerializer getInstance()
        This static method returns an instance of the default serializer. Normally this is the XStreamSerializer if the xstream library is detected in the classpath. If not the BinarySerializer (which requires the serialized objects to be Serializable) will be used as fallback.
        Returns:
        the default serializer
      • createObjectInputStream

        public abstract java.io.ObjectInputStream createObjectInputStream​(java.io.InputStream in)
                                                                   throws java.io.IOException
        Creates the ObjectInputStream that deserializes a stream of objects from an InputStream.
        Parameters:
        in - the input stream
        Returns:
        the object input stream
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • createObjectOutputStream

        public abstract java.io.ObjectOutputStream createObjectOutputStream​(java.io.OutputStream out)
                                                                     throws java.io.IOException
        Creates the ObjectOutputStream that serializees a stream of objects to the OutputStream.
        Parameters:
        out - the output stream
        Returns:
        the object output stream
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • load

        public java.lang.Object load​(java.io.File file)
                              throws java.io.IOException
        Loads a single ojbect from the given file.
        Parameters:
        file - the file
        Returns:
        the object
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • load

        public java.lang.Object load​(java.io.InputStream in)
                              throws java.io.IOException
        Loads a single ojbect from the given stream.
        Parameters:
        in - the in
        Returns:
        the object
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • save

        public void save​(java.lang.Object object,
                         java.io.File file)
                  throws java.io.IOException
        Saves a single object to the given file.
        Parameters:
        object - the object
        file - the file
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • save

        public void save​(java.lang.Object object,
                         java.io.OutputStream out)
                  throws java.io.IOException
        Saves a single object to the given stream.
        Parameters:
        object - the object
        out - the out
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.