|
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 |
58
| public static void serialize(Object pvObject, OutputStream pvOutputStream) throws IOException {
|
|
14 |
58
| ObjectOutputStream oos = new ObjectOutputStream(pvOutputStream);
|
|
15 |
58
| oos.writeObject(pvObject);
|
|
16 |
58
| oos.close();
|
|
17 |
| } |
|
18 |
| |
|
19 |
62
| public static byte[] serialize(Object pvObject) throws Exception {
|
|
20 |
62
| ByteArrayOutputStream lvArrayOutputStream = new ByteArrayOutputStream();
|
|
21 |
62
| ObjectOutputStream oos = new ObjectOutputStream(lvArrayOutputStream);
|
|
22 |
62
| oos.writeObject(pvObject);
|
|
23 |
61
| byte[] lvBytes = lvArrayOutputStream.toByteArray();
|
|
24 |
61
| oos.close();
|
|
25 |
61
| return lvBytes;
|
|
26 |
| } |
|
27 |
| |
|
28 |
116
| public static Object deserialize(InputStream pvInputStream) throws IOException, ClassNotFoundException {
|
|
29 |
116
| Object lvReturn = null;
|
|
30 |
116
| ObjectInputStream ois = new ObjectInputStream(pvInputStream);
|
|
31 |
116
| lvReturn = ois.readObject();
|
|
32 |
116
| ois.close();
|
|
33 |
116
| return lvReturn;
|
|
34 |
| } |
|
35 |
| |
|
36 |
1
| public static Object deserialize(byte pvBytes[]) throws IOException, ClassNotFoundException {
|
|
37 |
1
| Object lvReturn = null;
|
|
38 |
1
| ByteArrayInputStream lvArrayInputStream = new ByteArrayInputStream(pvBytes);
|
|
39 |
1
| ObjectInputStream ois = new ObjectInputStream(lvArrayInputStream);
|
|
40 |
1
| lvReturn = ois.readObject();
|
|
41 |
1
| ois.close();
|
|
42 |
1
| return lvReturn;
|
|
43 |
| } |
|
44 |
| |
|
45 |
| } |