edu.indiana.util
Class ObjectFileIO

java.lang.Object
  extended by edu.indiana.util.ObjectFileIO

public class ObjectFileIO
extends java.lang.Object

This class facilitates writing objects to files. Make sure that every object that is written (and its components) implement Serializable!


Constructor Summary
ObjectFileIO(boolean showMessages)
          Creates new ObjectFileIO
 
Method Summary
 boolean beginReadObjectFromFile(java.lang.String filename)
          Open a file and prepare it for reading objects.
 boolean beginWriteObjectToFile(java.lang.String filename)
          Open a file and prepare it for writing objects.
 boolean endReadObjectFromFile()
          Finish reading from the file opened with beginReadObjectFromFile().
 boolean endWriteObjectToFile()
          Finish writing to the file opened with beginWriteObjectToFile().
 java.lang.Object readObject()
          Read an object from the file opened with beginReadObjectFromFile().
static java.lang.Object readOneObjectFromFile(java.lang.String filename, boolean showMessages)
          Read a single object from a file, and return it.
 boolean writeObject(java.lang.Object o)
          Write an object to the file opened with beginWriteObjectToFile().
static boolean writeOneObjectToFile(java.lang.Object obj, java.lang.String filename, boolean showMessages)
          Write a single object to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectFileIO

public ObjectFileIO(boolean showMessages)
Creates new ObjectFileIO

Method Detail

readOneObjectFromFile

public static java.lang.Object readOneObjectFromFile(java.lang.String filename,
                                                     boolean showMessages)
Read a single object from a file, and return it. The first object in file filename is read and returned; if there are additional objects in the file, they are ignored. Handles all opening and closing of the file.

Parameters:
filename - The name of the file to be read.
Returns:
The object read

writeOneObjectToFile

public static boolean writeOneObjectToFile(java.lang.Object obj,
                                           java.lang.String filename,
                                           boolean showMessages)
Write a single object to a file. Any pre-existing file contents are destroyed. Handles all opening and closing of the file.

Parameters:
obj - The object to be written to the file.
filename - The file name of the file to be written.
Returns:
true if successful, false otherwise.

beginWriteObjectToFile

public final boolean beginWriteObjectToFile(java.lang.String filename)
Open a file and prepare it for writing objects. Any pre-existing contents of the file are destroyed.

Parameters:
filename - The name of the file that will be written.
Returns:
true if step was successful, false otherwise.

writeObject

public final boolean writeObject(java.lang.Object o)
Write an object to the file opened with beginWriteObjectToFile().

Parameters:
o - The object to write.
Returns:
true if successful, false otherwise.

endWriteObjectToFile

public final boolean endWriteObjectToFile()
Finish writing to the file opened with beginWriteObjectToFile(). Handles all file closings.

Returns:
true if successful, false otherwise.

beginReadObjectFromFile

public final boolean beginReadObjectFromFile(java.lang.String filename)
Open a file and prepare it for reading objects.

Parameters:
filename - The name of the file that will be read.
Returns:
true if step was successful, false otherwise.

readObject

public final java.lang.Object readObject()
Read an object from the file opened with beginReadObjectFromFile().

Parameters:
o - The object to read.
Returns:
The object read, or null if there are no more objects in the file.

endReadObjectFromFile

public final boolean endReadObjectFromFile()
Finish reading from the file opened with beginReadObjectFromFile(). Handles all file closings.

Returns:
true if successful, false otherwise.