1 package org.apache.directmemory.serialization;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.ByteArrayOutputStream;
23 import java.io.IOException;
24 import java.io.ObjectOutputStream;
25
26 import org.apache.directmemory.measures.Ram;
27 import org.apache.directmemory.misc.DummyPojo;
28
29 public final class DummyPojoSerializer
30 implements Serializer
31 {
32
33 final DummyPojo pojo = new DummyPojo( "test", Ram.Kb( 2 ) );
34
35 final byte[] data;
36
37 public DummyPojoSerializer()
38 {
39 ByteArrayOutputStream baos = new ByteArrayOutputStream();
40 try
41 {
42 ObjectOutputStream oos = new ObjectOutputStream( baos );
43 oos.writeObject( pojo );
44 oos.flush();
45 oos.close();
46 }
47 catch ( Exception e )
48 {
49
50 }
51 data = baos.toByteArray();
52 }
53
54 @SuppressWarnings( "unchecked" )
55 @Override
56 public <T> T deserialize( byte[] source, Class<T> clazz )
57 throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
58 {
59
60 return (T) pojo;
61 }
62
63 @Override
64 public <T> byte[] serialize( T obj )
65 throws IOException
66 {
67 return data;
68 }
69
70 }