-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathClass_Catalog.java
More file actions
60 lines (44 loc) · 1.66 KB
/
Class_Catalog.java
File metadata and controls
60 lines (44 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package examples;
import org.junit.Test;
import org.mapdb.elsa.ElsaMaker;
import org.mapdb.elsa.ElsaSerializerPojo;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.Serializable;
import static org.junit.Assert.assertTrue;
/**
* Shows how class catalog can reduce data usage
*/
public class Class_Catalog {
/** this class is serialized using object graph */
public static class Bean implements Serializable {
final int someData;
public Bean(int someData) {
this.someData = someData;
}
}
@Test
public void withCatalog() throws IOException {
//data for serialization
Object data = new Bean(11);
//serialize without using class catalog
ByteArrayOutputStream out = new ByteArrayOutputStream();
DataOutputStream out2 = new DataOutputStream(out);
ElsaSerializerPojo serializer = new ElsaMaker().make();
serializer.serialize(out2, data);
int sizeWithoutCatalog = out.toByteArray().length;
//serialize with using class catalog
out = new ByteArrayOutputStream();
out2 = new DataOutputStream(out);
serializer = new ElsaMaker()
//this registers Bean class into class catalog
.registerClasses(Bean.class)
.make();
serializer.serialize(out2, data);
int sizeWithCatalog = out.toByteArray().length;
System.out.println("Size without Class Catalog : "+sizeWithoutCatalog);
System.out.println("Size with Class Catalog : "+sizeWithCatalog);
assertTrue(sizeWithoutCatalog>sizeWithCatalog);
}
}