Package serialize

Source Code of serialize.Serializer

package serialize;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import History.Memento;

public class Serializer
{
  public static void Serialize(Memento memento, File file)
  {
    try
    {
      ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
      oos.writeObject(new HistoryStackSer(memento.getStack()));
      oos.close();
    } catch (Exception e)
    {
      System.err.println("Error on saving project");
      e.printStackTrace();
    }
  }

  public static Memento Deserialize(File file)
  {
    try
    {
      ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
      HistoryStackSer stack = (HistoryStackSer) ois.readObject();
      Memento memento = new Memento();
      memento.setStack(stack.getHistoryStack());
      ois.close();

      return memento;
    } catch (Exception e)
    {
      System.err.println("Error on opening project");
      e.printStackTrace();
    }

    return null;
  }
}
TOP

Related Classes of serialize.Serializer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.