1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| package org.jboss.cache.marshall; |
9 |
| |
10 |
| import org.jboss.util.stream.MarshalledValueInputStream; |
11 |
| import org.jboss.util.stream.MarshalledValueOutputStream; |
12 |
| |
13 |
| import java.io.ByteArrayInputStream; |
14 |
| import java.io.ByteArrayOutputStream; |
15 |
| import java.io.InputStream; |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| public class MarshallUtil |
24 |
| { |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
0
| public static Object objectFromByteBuffer(byte[] bytes) throws Exception
|
35 |
| { |
36 |
0
| if (bytes == null)
|
37 |
| { |
38 |
0
| return null;
|
39 |
| } |
40 |
| |
41 |
0
| ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
42 |
0
| MarshalledValueInputStream input = new MarshalledValueInputStream(bais);
|
43 |
0
| Object result = input.readObject();
|
44 |
0
| input.close();
|
45 |
0
| return result;
|
46 |
| } |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
0
| public static Object objectFromByteBuffer(InputStream bytes) throws Exception
|
57 |
| { |
58 |
0
| if (bytes == null)
|
59 |
| { |
60 |
0
| return null;
|
61 |
| } |
62 |
| |
63 |
0
| MarshalledValueInputStream input = new MarshalledValueInputStream(bytes);
|
64 |
0
| Object result = input.readObject();
|
65 |
0
| input.close();
|
66 |
0
| return result;
|
67 |
| } |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
0
| public static byte[] objectToByteBuffer(Object obj) throws Exception
|
77 |
| { |
78 |
0
| ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
79 |
0
| MarshalledValueOutputStream out = new MarshalledValueOutputStream(baos);
|
80 |
0
| out.writeObject(obj);
|
81 |
0
| out.close();
|
82 |
0
| return baos.toByteArray();
|
83 |
| } |
84 |
| |
85 |
| } |