gov.sandia.cognition.framework.io
Class SerializedModelHandler

java.lang.Object
  extended by gov.sandia.cognition.framework.io.SerializedModelHandler

public class SerializedModelHandler
extends Object

The SerializedModelHandler class implements some utility methods for dealing with models that have been serialized using the Java serialization API.

Since:
1.0
Author:
Justin Basilico

Constructor Summary
protected SerializedModelHandler()
          Creates a new instance of SerializedModelHandler
 
Method Summary
static CognitiveModel readModelFromFile(File file)
          Reads a serialized CognitiveModel from the given file.
static CognitiveModel readModelFromFile(String fileName)
          Reads a serialized CognitiveModel from the given file.
static Object readObjectFromFile(File file)
          Reads a serialized Java Object from the given File.
static void writeModelToFile(File file, CognitiveModel model)
          Writes the given CognitiveModel to the given file using Java object serialization
static void writeModelToFile(String fileName, CognitiveModel model)
          Writes the given CognitiveModel to the given file using Java object serialization
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerializedModelHandler

protected SerializedModelHandler()
Creates a new instance of SerializedModelHandler

Method Detail

readObjectFromFile

public static Object readObjectFromFile(File file)
                                 throws FileNotFoundException,
                                        ClassNotFoundException,
                                        IOException
Reads a serialized Java Object from the given File.

Parameters:
file - The File to read from.
Returns:
The Object read from the given File.
Throws:
FileNotFoundException - If the file was not found.
ClassNotFoundException - If the class that the Object or one of its internal fields cannot be found.
IOException - If there is any other type of error reading from the file.

readModelFromFile

public static CognitiveModel readModelFromFile(String fileName)
                                        throws FileNotFoundException,
                                               ClassNotFoundException,
                                               IOException
Reads a serialized CognitiveModel from the given file.

Parameters:
fileName - The name of the file to read from.
Returns:
The CognitiveModel read from the given File.
Throws:
FileNotFoundException - If the file was not found.
ClassNotFoundException - If a class in the file cannot be found.
IOException - If there is any other type of error reading from the file.

readModelFromFile

public static CognitiveModel readModelFromFile(File file)
                                        throws FileNotFoundException,
                                               ClassNotFoundException,
                                               IOException
Reads a serialized CognitiveModel from the given file.

Parameters:
file - The file to read from.
Returns:
The CognitiveModel read from the given File.
Throws:
FileNotFoundException - If the file was not found.
ClassNotFoundException - If a class in the file cannot be found.
IOException - If there is any other type of error reading from the file.

writeModelToFile

public static void writeModelToFile(String fileName,
                                    CognitiveModel model)
                             throws IOException
Writes the given CognitiveModel to the given file using Java object serialization

Parameters:
fileName - The name of the file to write to.
model - The model to serialize into the file.
Throws:
IOException - If there was an error writing the object.

writeModelToFile

public static void writeModelToFile(File file,
                                    CognitiveModel model)
                             throws IOException
Writes the given CognitiveModel to the given file using Java object serialization

Parameters:
file - The File to write to.
model - The model to serialize into the file.
Throws:
IOException - If there was an error writing the object.