package org.anyline.util; 
 
import java.io.ByteArrayInputStream; 
import java.io.ByteArrayOutputStream; 
import java.io.IOException; 
import java.io.ObjectInputStream; 
import java.io.ObjectOutputStream; 
 
public class ObjectUtil { 
	public static byte[] serialize(Object obj) { 
		ObjectOutputStream obi = null; 
		ByteArrayOutputStream bai = null; 
		try { 
			bai = new ByteArrayOutputStream(); 
			obi = new ObjectOutputStream(bai); 
			obi.writeObject(obj); 
			byte[] byt = bai.toByteArray(); 
			return byt; 
		} catch (IOException e) { 
			e.printStackTrace(); 
		} 
		return null; 
	} 
 
	public static Object unserizlize(byte[] byt) { 
		ObjectInputStream oii = null; 
		ByteArrayInputStream bis = null; 
		bis = new ByteArrayInputStream(byt); 
		try { 
			oii = new ObjectInputStream(bis); 
			Object obj = oii.readObject(); 
			return obj; 
		} catch (Exception e) { 
 
			e.printStackTrace(); 
		} 
		return null; 
	} 
} 
