import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;import org.apache.commons.codec.binary.Base64;
public class Serializer {
public static String serialize(Serializable obj) throws IOException {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
GZIPOutputStream gzipout = new GZIPOutputStream(bout);
ObjectOutputStream objout = new ObjectOutputStream(gzipout);
objout.writeObject(obj);
objout.flush();
gzipout.finish();
return new String(Base64.encodeBase64(bout.toByteArray()));
}public static Object unserialize(String encoded) throws IOException,
ClassNotFoundException {
byte[] src = Base64.decodeBase64(encoded.getBytes());
ByteArrayInputStream bin = new ByteArrayInputStream(src);
GZIPInputStream gzipin = new GZIPInputStream(bin, src.length);
ObjectInputStream objin = new ObjectInputStream(gzipin);
return objin.readObject();
}}