import java.io.*;

/**
 *  Caretaker of a snapshot of the Othello's board.
 * The snapshot is help in a variable.
 */

public class Caretaker {
    private String filename = "snapshot";
    
    /**
     *  Hold the snapshot passed as argument
     *  @param snapshot The snapshot
     */
    void set(Serializable snapshot) {
	try {
	    ObjectOutputStream out =
		new ObjectOutputStream (new FileOutputStream (filename));
	    out.writeObject (snapshot);
	    out.close ();
	} catch (Exception e) { e.printStackTrace (); }
    }
    
    /**
     *  Return the snapshot helf, if any
     *  @return the snapshot
     */
    Serializable get()  {
	try {
	    ObjectInputStream in =
		new ObjectInputStream (
		    new FileInputStream (filename));
	    return (Serializable) in.readObject ();
	} catch (Exception e) {
	    e.printStackTrace ();
	    throw new RuntimeException (e.getMessage ());
	}
    }

}
