| 35 | public class ObjectSerializer { |
| 36 | |
| 37 | public static String serialize(Serializable obj) throws IOException { |
| 38 | if (obj == null) |
| 39 | return ""; |
| 40 | try { |
| 41 | ByteArrayOutputStream serialObj = new ByteArrayOutputStream(); |
| 42 | Deflater def = new Deflater(Deflater.BEST_COMPRESSION); |
| 43 | ObjectOutputStream objStream = new ObjectOutputStream(new DeflaterOutputStream( |
| 44 | serialObj, def)); |
| 45 | objStream.writeObject(obj); |
| 46 | objStream.close(); |
| 47 | return encodeBytes(serialObj.toByteArray()); |
| 48 | } catch (Exception e) { |
| 49 | throw new IOException("Serialization error: " + e.getMessage(), e); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | public static Object deserialize(String str) throws IOException { |
| 54 | if (str == null || str.length() == 0) |