
package edu.unl.consystlab.util;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

public class Persistent
{
	public static boolean save(String fileName, Object o)
	{
		try {
			return save(new FileOutputStream(fileName), o);
		} catch (Exception e) {}
		return false;		
	}
	
	public static boolean save(OutputStream os, Object o) 
	{
		try{
			ObjectOutputStream oos = new ObjectOutputStream(os);
			oos.writeObject(o);
			oos.close();
			return true;
		} catch (Exception e) {}
		return false;
	}
	
	public static Object load(String fileName)
	{
		try {
			return load(new FileInputStream(fileName));
		} catch (Exception e) {}
		return null;
	}
	
	public static Object load(InputStream is) 
	{
		try{
			ObjectInputStream ois = new ObjectInputStream(is);
			return ois.readObject();
		} catch (Exception e) {}
		return null;
	}
	
	
}
