gov.sandia.cognition.io.serialization
Class AbstractStreamSerializationHandler<SerializedType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.io.serialization.AbstractFileSerializationHandler<SerializedType>
          extended by gov.sandia.cognition.io.serialization.AbstractStreamSerializationHandler<SerializedType>
Type Parameters:
SerializedType - The type of object that can be serialized.
All Implemented Interfaces:
FileSerializationHandler<SerializedType>, StreamSerializationHandler<SerializedType>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
AbstractTextSerializationHandler, GZIPSerializationHandler, JavaDefaultBinarySerializationHandler

public abstract class AbstractStreamSerializationHandler<SerializedType>
extends AbstractFileSerializationHandler<SerializedType>
implements StreamSerializationHandler<SerializedType>

An abstract implementation of StreamSerializationHandler. Handles the file and byte reading aspects so all you need to implement is the write and read methods.

Since:
3.0
Author:
Justin Basilico
See Also:
Serialized Form

Constructor Summary
AbstractStreamSerializationHandler()
          Creates a new AbstractStreamSerializationHandler.
 
Method Summary
 Object convertFromBytes(byte[] bytes)
          Converts the first given object in the given byte array.
 byte[] convertToBytes(SerializedType object)
          Converts the given object to bytes.
 Object readFromFile(File file)
          Reads an object from the given file.
 void writeToFile(File file, SerializedType object)
          Reads an object from a given file.
 
Methods inherited from class gov.sandia.cognition.io.serialization.AbstractFileSerializationHandler
readFromFile, writeToFile
 
Methods inherited from class gov.sandia.cognition.util.AbstractCloneableSerializable
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.io.serialization.StreamSerializationHandler
readObject, writeObject
 
Methods inherited from interface gov.sandia.cognition.io.serialization.FileSerializationHandler
readFromFile, writeToFile
 

Constructor Detail

AbstractStreamSerializationHandler

public AbstractStreamSerializationHandler()
Creates a new AbstractStreamSerializationHandler.

Method Detail

writeToFile

public void writeToFile(File file,
                        SerializedType object)
                 throws IOException
Description copied from interface: FileSerializationHandler
Reads an object from a given file.

Specified by:
writeToFile in interface FileSerializationHandler<SerializedType>
Parameters:
file - The file to write the object to.
object - The object to write.
Throws:
IOException - If there is an i/o error.

readFromFile

public Object readFromFile(File file)
                    throws IOException,
                           ClassNotFoundException
Description copied from interface: FileSerializationHandler
Reads an object from the given file.

Specified by:
readFromFile in interface FileSerializationHandler<SerializedType>
Parameters:
file - The file to read an object from.
Returns:
The object read from the file.
Throws:
IOException - If there is an i/o error.
ClassNotFoundException - If a class cannot be found.

convertToBytes

public byte[] convertToBytes(SerializedType object)
                      throws IOException
Description copied from interface: StreamSerializationHandler
Converts the given object to bytes.

Specified by:
convertToBytes in interface StreamSerializationHandler<SerializedType>
Parameters:
object - The object to convert to bytes.
Returns:
The byte representation of the object.
Throws:
IOException - If there is an i/o error.

convertFromBytes

public Object convertFromBytes(byte[] bytes)
                        throws IOException,
                               ClassNotFoundException
Description copied from interface: StreamSerializationHandler
Converts the first given object in the given byte array.

Specified by:
convertFromBytes in interface StreamSerializationHandler<SerializedType>
Parameters:
bytes - The bytes to convert the object from.
Returns:
The first object represented by the given bytes.
Throws:
IOException - If there is an i/o error.
ClassNotFoundException - If a class cannot be found.