1
14
15 package com.liferay.portal.kernel.util;
16
17 import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream;
18 import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream;
19
20 import java.io.IOException;
21 import java.io.ObjectInputStream;
22 import java.io.ObjectOutputStream;
23
24
29 public class SerializableUtil {
30
31 public static Object deserialize(byte[] bytes)
32 throws ClassNotFoundException, IOException {
33
34 ObjectInputStream ois = null;
35
36 try {
37 ois = new ObjectInputStream(new UnsyncByteArrayInputStream(bytes));
38
39 Object obj = ois.readObject();
40
41 ois.close();
42
43 ois = null;
44
45 return obj;
46 }
47 finally {
48 if (ois != null) {
49 ois.close();
50 }
51 }
52 }
53
54 public static byte[] serialize(Object obj) throws IOException {
55 ObjectOutputStream oos = null;
56
57 try {
58 UnsyncByteArrayOutputStream ubaos =
59 new UnsyncByteArrayOutputStream();
60
61 oos = new ObjectOutputStream(ubaos);
62
63 oos.writeObject(obj);
64
65 oos.close();
66
67 oos = null;
68
69 return ubaos.toByteArray();
70 }
71 finally {
72 if (oos != null) {
73 oos.close();
74 }
75 }
76 }
77
78 }