
/**
 * BinaryFileManager2.java
 * This class handels the input and output of binary files for the LabFile 
 * program.
 *
 * Created: Sat Jun 24 11:05:12 2000
 *
 * @author Nathan Stevens
 * @version 0.11 03/20/06
 */
import java.io.*;

public class BinaryFileManager2 {
  public BinaryFileManager2() { }
  
  // Method to return a donor acceptor list
  public DonorAcceptorData getDonorAcceptorData(File file) {
    DonorAcceptorData daData = (DonorAcceptorData)getObjectFromFile(file);
    return daData;
  }
  
  // Method to read an object from a file
  public Object getObjectFromFile(File file) {
    try {	
      // Create the output stream object
      ObjectInputStream in = 
        new ObjectInputStream(
        new BufferedInputStream(
        new FileInputStream(file)));
      
      Object object =  in.readObject();
      in.close();
      
      return object;
    }
		catch(IOException e) {
      System.err.println("The following error ocurred in the BinaryFileManager2\n" + e);          
		}
		catch(ClassNotFoundException e) {
			System.err.println("The following error occured in the BinaryFileManager2\n" + e);
		}
		// if we catched an exception just return null
    return null;
	}
  
  // Method to save an object to a file
  public void saveObjectToFile(Object object, File file) {
		try {
			// Create the object ouput stream
      ObjectOutputStream out = 
				new ObjectOutputStream(
				new BufferedOutputStream(
        new FileOutputStream(file)));
      
			out.writeObject(object);
			out.close();
		}
		catch(IOException e) {
			System.err.println("IO exception in the BinaryFileManager2\n" + e);
		}
  }
} // --end class BinaryFileManager2
