1 package net.sf.crispy.impl.http; 2 3 import java.io.ByteArrayInputStream; 4 import java.io.ByteArrayOutputStream; 5 import java.io.IOException; 6 import java.io.InputStream; 7 import java.io.ObjectInputStream; 8 import java.io.ObjectOutputStream; 9 import java.io.OutputStream; 10 11 public class Serializer { 12 13 public static void serialize(Object pvObject, OutputStream pvOutputStream) throws IOException { 14 ObjectOutputStream oos = new ObjectOutputStream(pvOutputStream); 15 oos.writeObject(pvObject); 16 oos.close(); 17 } 18 19 public static byte[] serialize(Object pvObject) throws Exception { 20 ByteArrayOutputStream lvArrayOutputStream = new ByteArrayOutputStream(); 21 ObjectOutputStream oos = new ObjectOutputStream(lvArrayOutputStream); 22 oos.writeObject(pvObject); 23 byte[] lvBytes = lvArrayOutputStream.toByteArray(); 24 oos.close(); 25 return lvBytes; 26 } 27 28 public static Object deserialize(InputStream pvInputStream) throws IOException, ClassNotFoundException { 29 Object lvReturn = null; 30 ObjectInputStream ois = new ObjectInputStream(pvInputStream); 31 lvReturn = ois.readObject(); 32 ois.close(); 33 return lvReturn; 34 } 35 36 public static Object deserialize(byte pvBytes[]) throws IOException, ClassNotFoundException { 37 Object lvReturn = null; 38 ByteArrayInputStream lvArrayInputStream = new ByteArrayInputStream(pvBytes); 39 ObjectInputStream ois = new ObjectInputStream(lvArrayInputStream); 40 lvReturn = ois.readObject(); 41 ois.close(); 42 return lvReturn; 43 } 44 45 }