1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.avltree;
21
22
23 import java.io.ByteArrayInputStream;
24 import java.io.ByteArrayOutputStream;
25 import java.io.IOException;
26 import java.io.ObjectInputStream;
27 import java.io.ObjectOutputStream;
28
29 import org.apache.directory.server.i18n.I18n;
30
31
32
33
34
35
36
37 public class DefaultMarshaller implements Marshaller<Object>
38 {
39 public static final DefaultMarshallerltree/DefaultMarshaller.html#DefaultMarshaller">DefaultMarshaller INSTANCE = new DefaultMarshaller();
40
41
42 public byte[] serialize( Object object ) throws IOException
43 {
44 try ( ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
45 ObjectOutputStream out = new ObjectOutputStream( byteStream ) )
46 {
47 out.writeObject( object );
48 out.flush();
49 byte[] data = byteStream.toByteArray();
50
51 return data;
52 }
53 }
54
55
56 public Object deserialize( byte[] bytes ) throws IOException
57 {
58 try ( ByteArrayInputStream byteStream = new ByteArrayInputStream( bytes );
59 ObjectInputStream in = new ObjectInputStream( byteStream ) )
60 {
61 return in.readObject();
62 }
63 catch ( ClassNotFoundException e )
64 {
65 IOException ioe = new IOException( I18n.err( I18n.ERR_445 ) );
66 ioe.initCause( e );
67 throw ioe;
68 }
69 }
70 }