p3j.misc
Class Serializer

java.lang.Object
  extended by p3j.misc.Serializer

public class Serializer
extends Object

Class that stores and loads serializable classes. Needed to store and load parameter files. Created on February 12, 2007

Author:
Christina Bohk, Roland Ewald

Constructor Summary
Serializer()
           
 
Method Summary
protected  InputStream getInputStream(String file)
          Create an input stream.
protected  OutputStream getOutputStream(String file)
          Create an output stream.
 boolean isUsingXML()
           
 Object load(String file)
          Loads object from file.
 Object loadFromBinary(String file)
          Load object from a binary file.
 Object loadFromXML(String file)
          Load object from XML file.
 void save(Object object, String file)
          Save object to file.
 void saveToBinary(Object object, String file)
          Save object to binary file.
 void saveToXML(Object object, String file)
          Save object to XML file.
 void setUsingXML(boolean usingXML)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Serializer

public Serializer()
Method Detail

load

public Object load(String file)
            throws IOException,
                   ClassNotFoundException
Loads object from file.

Parameters:
file - path to file with the object to be loaded
Returns:
object the object that has been loaded
Throws:
IOException - if file was not found, file input failed, etc.
ClassNotFoundException - if class of persistent object could not be found

loadFromBinary

public Object loadFromBinary(String file)
                      throws IOException,
                             ClassNotFoundException
Load object from a binary file.

Parameters:
file - path and file name
Returns:
deserialised object
Throws:
IOException - if file was not found, etc.
ClassNotFoundException - if class of persistent object could not be found

loadFromXML

public Object loadFromXML(String file)
                   throws IOException
Load object from XML file.

Parameters:
file - path and file name
Returns:
deserialised object
Throws:
IOException - if file was not found, a read error occurred, etc.

getInputStream

protected InputStream getInputStream(String file)
                              throws IOException
Create an input stream.

Parameters:
file - source file
Returns:
input stream from file
Throws:
IOException - if stream creation fails

getOutputStream

protected OutputStream getOutputStream(String file)
                                throws IOException
Create an output stream.

Parameters:
file - target file
Returns:
output stream to file
Throws:
IOException - if stream creation fails

save

public void save(Object object,
                 String file)
          throws IOException
Save object to file.

Parameters:
object - the object to be saved in the file
file - the file
Throws:
IOException - if outputting went wrong

saveToBinary

public void saveToBinary(Object object,
                         String file)
                  throws IOException
Save object to binary file.

Parameters:
object - the object to be written
file - the target file
Throws:
IOException - if writing fails

saveToXML

public void saveToXML(Object object,
                      String file)
               throws IOException
Save object to XML file.

Parameters:
object - the object to be written
file - the target file
Throws:
IOException - if writing fails

isUsingXML

public boolean isUsingXML()

setUsingXML

public void setUsingXML(boolean usingXML)


Copyright © 2012. All Rights Reserved.