org.onebusaway.utility
Class ObjectSerializationLibrary

java.lang.Object
  extended by org.onebusaway.utility.ObjectSerializationLibrary

public class ObjectSerializationLibrary
extends Object

Convenience methods for serializing objects to and from streams and files.

Author:
bdferris

Constructor Summary
ObjectSerializationLibrary()
           
 
Method Summary
static ObjectInputStream getFileAsObjectInputStream(File file)
          Convenience method to open a specified file as an ObjectInputStream
static ObjectOutputStream getFileAsObjectOutputStream(File file)
          Convenience method to open a specified file as an ObjectOutputStream
static void main(String[] args)
           
static void printObject(File file, Object o)
          Convenience method to serialize the string representation of an object, as returned by the Object.toString() method, to a file.
static
<T> T
readObject(File file)
          Read an object from a file by opening the file as an ObjectInputStream and reading a single object from the stream.
static void writeObject(File file, Object o)
          Serialize an object to a file by opening an ObjectOutputStream linked to the file and writing the object to the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectSerializationLibrary

public ObjectSerializationLibrary()
Method Detail

main

public static void main(String[] args)
                 throws IOException,
                        ClassNotFoundException
Throws:
IOException
ClassNotFoundException

getFileAsObjectOutputStream

public static ObjectOutputStream getFileAsObjectOutputStream(File file)
                                                      throws IOException
Convenience method to open a specified file as an ObjectOutputStream

Parameters:
file - the target output file
Returns:
an ObjectOutputStream linked to the target file
Throws:
IOException

getFileAsObjectInputStream

public static ObjectInputStream getFileAsObjectInputStream(File file)
                                                    throws IOException
Convenience method to open a specified file as an ObjectInputStream

Parameters:
file - the target input file
Returns:
an ObjectInputStream linked to the target file
Throws:
IOException

writeObject

public static void writeObject(File file,
                               Object o)
                        throws IOException
Serialize an object to a file by opening an ObjectOutputStream linked to the file and writing the object to the stream.

Parameters:
file - the target output file
o - the object to serialize
Throws:
IOException

readObject

public static <T> T readObject(File file)
                    throws IOException,
                           ClassNotFoundException
Read an object from a file by opening the file as an ObjectInputStream and reading a single object from the stream.

Parameters:
file - the input file
Returns:
an object deserialized from the file
Throws:
IOException
ClassNotFoundException

printObject

public static void printObject(File file,
                               Object o)
                        throws IOException
Convenience method to serialize the string representation of an object, as returned by the Object.toString() method, to a file.

Parameters:
file - the target output file
o - the object to serialize
Throws:
IOException


Copyright © 2011 OneBusAway. All Rights Reserved.