patterntesting.runtime.io
Class AbstractSerializer

Package class diagram package AbstractSerializer
java.lang.Object
  extended by patterntesting.runtime.io.AbstractSerializer
Direct Known Subclasses:
BinarySerializer, XStreamSerializer

public abstract class AbstractSerializer
extends 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

Constructor Summary
AbstractSerializer()
           
 
Method Summary
abstract  ObjectInputStream createObjectInputStream(InputStream in)
          Creates the ObjectInputStream that deserializes a stream of objects from an InputStream.
abstract  ObjectOutputStream createObjectOutputStream(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.
 Object load(File file)
          Loads a single ojbect from the given file.
 Object load(InputStream in)
          Loads a single ojbect from the given stream.
 void save(Object object, File file)
          Saves a single object to the given file.
 void save(Object object, 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 ObjectInputStream createObjectInputStream(InputStream in)
                                                   throws IOException
Creates the ObjectInputStream that deserializes a stream of objects from an InputStream.

Parameters:
in - the input stream
Returns:
the object input stream
Throws:
IOException - Signals that an I/O exception has occurred.

createObjectOutputStream

public abstract ObjectOutputStream createObjectOutputStream(OutputStream out)
                                                     throws IOException
Creates the ObjectOutputStream that serializees a stream of objects to the OutputStream.

Parameters:
out - the output stream
Returns:
the object output stream
Throws:
IOException - Signals that an I/O exception has occurred.

load

public Object load(File file)
            throws IOException,
                   ClassNotFoundException
Loads a single ojbect from the given file.

Parameters:
file - the file
Returns:
the object
Throws:
IOException - Signals that an I/O exception has occurred.
ClassNotFoundException - the class not found exception

load

public Object load(InputStream in)
            throws IOException,
                   ClassNotFoundException
Loads a single ojbect from the given stream.

Parameters:
in - the in
Returns:
the object
Throws:
IOException - Signals that an I/O exception has occurred.
ClassNotFoundException - the class not found exception

save

public void save(Object object,
                 File file)
          throws IOException
Saves a single object to the given file.

Parameters:
object - the object
file - the file
Throws:
IOException - Signals that an I/O exception has occurred.

save

public void save(Object object,
                 OutputStream out)
          throws IOException
Saves a single object to the given stream.

Parameters:
object - the object
out - the out
Throws:
IOException - Signals that an I/O exception has occurred.


Copyright © 2002–2014 PatternTesting Team. All rights reserved.