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.partition.impl.btree.jdbm;
21
22
23 import jdbm.helper.Serializer;
24
25 import java.io.IOException;
26
27
28
29
30
31
32
33
34 public class LongSerializer implements Serializer
35 {
36 private static final long serialVersionUID = 237756689544852128L;
37 public static final LongSerializer INSTANCE = new LongSerializer();
38
39
40 public byte[] serialize( Object o ) throws IOException
41 {
42 long id = ( Long ) o;
43 byte[] bites = new byte[8];
44
45 bites[0] = ( byte ) ( id >> 56 );
46 bites[1] = ( byte ) ( id >> 48 );
47 bites[2] = ( byte ) ( id >> 40 );
48 bites[3] = ( byte ) ( id >> 32 );
49 bites[4] = ( byte ) ( id >> 24 );
50 bites[5] = ( byte ) ( id >> 16 );
51 bites[6] = ( byte ) ( id >> 8 );
52 bites[7] = ( byte ) id;
53
54 return bites;
55 }
56
57
58 public Object deserialize( byte[] bites ) throws IOException
59 {
60 long id;
61 id = bites[0] + ( ( bites[0] < 0 ) ? 256 : 0 );
62 id <<= 8;
63 id += bites[1] + ( ( bites[1] < 0 ) ? 256 : 0 );
64 id <<= 8;
65 id += bites[2] + ( ( bites[2] < 0 ) ? 256 : 0 );
66 id <<= 8;
67 id += bites[3] + ( ( bites[3] < 0 ) ? 256 : 0 );
68 id <<= 8;
69 id += bites[4] + ( ( bites[4] < 0 ) ? 256 : 0 );
70 id <<= 8;
71 id += bites[5] + ( ( bites[5] < 0 ) ? 256 : 0 );
72 id <<= 8;
73 id += bites[6] + ( ( bites[6] < 0 ) ? 256 : 0 );
74 id <<= 8;
75 id += bites[7] + ( ( bites[7] < 0 ) ? 256 : 0 );
76 return id;
77 }
78 }