1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.mitosis.operation;
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 import java.io.ObjectStreamConstants;
29
30 import org.apache.directory.server.schema.registries.Registries;
31
32
33
34
35
36
37
38
39 public class OperationCodec
40 {
41 public OperationCodec()
42 {
43 }
44
45
46
47
48
49 public byte[] encode( Operation op )
50 {
51 ByteArrayOutputStream bout = new ByteArrayOutputStream();
52 try
53 {
54 ObjectOutputStream out = new ObjectOutputStream( bout );
55 out.useProtocolVersion( ObjectStreamConstants.PROTOCOL_VERSION_2 );
56 Operation.serialize( op, out );
57 out.flush();
58 out.close();
59 }
60 catch ( IOException e )
61 {
62 throw ( InternalError ) new InternalError().initCause( e );
63 }
64 catch ( ClassNotFoundException cnfe )
65 {
66 throw ( InternalError ) new InternalError().initCause( cnfe );
67 }
68
69 return bout.toByteArray();
70 }
71
72
73
74
75
76 public Operation decode( Registries registries, byte[] data )
77 {
78 ObjectInputStream in;
79
80 try
81 {
82 in = new ObjectInputStream( new ByteArrayInputStream( data ) );
83 return Operation.deserialize( registries, in );
84 }
85 catch ( IOException e )
86 {
87 throw ( InternalError ) new InternalError().initCause( e );
88 }
89 catch ( ClassNotFoundException e )
90 {
91 throw ( InternalError ) new InternalError().initCause( e );
92 }
93 }
94 }