1 49 package org.exolab.jms.tranlog; 50 51 52 import java.io.ByteArrayInputStream ; 53 import java.io.ByteArrayOutputStream ; 54 import java.io.IOException ; 55 import java.io.ObjectInputStream ; 56 import java.io.ObjectOutputStream ; 57 58 59 63 public class SerializationHelper { 64 65 72 static public byte[] serialize(Object object) 73 throws IOException { 74 75 ByteArrayOutputStream bstream = new ByteArrayOutputStream (); 76 ObjectOutputStream ostream = new ObjectOutputStream (bstream); 77 ostream.writeObject(object); 78 79 return bstream.toByteArray(); 80 } 81 82 94 static public Object deserialize(byte[] blob) 95 throws IOException , ClassNotFoundException { 96 97 if (blob == null) { 98 throw new IllegalArgumentException ("null blob to deserialize"); 99 } 100 101 ByteArrayInputStream bstream = new ByteArrayInputStream (blob); 102 ObjectInputStream istream = new ObjectInputStream (bstream); 103 104 return istream.readObject(); 105 } 106 } 107 | Popular Tags |