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 public class LongSerializer implements Serializer
34 {
35 private static final long serialVersionUID = 237756689544852128L;
36 public static final LongSerializerrver/core/partition/impl/btree/jdbm/LongSerializer.html#LongSerializer">LongSerializer INSTANCE = new LongSerializer();
37
38
39 public byte[] serialize( Object o ) throws IOException
40 {
41 long id = ( Long ) o;
42 byte[] bites = new byte[8];
43
44 bites[0] = ( byte ) ( id >> 56 );
45 bites[1] = ( byte ) ( id >> 48 );
46 bites[2] = ( byte ) ( id >> 40 );
47 bites[3] = ( byte ) ( id >> 32 );
48 bites[4] = ( byte ) ( id >> 24 );
49 bites[5] = ( byte ) ( id >> 16 );
50 bites[6] = ( byte ) ( id >> 8 );
51 bites[7] = ( byte ) id;
52
53 return bites;
54 }
55
56
57 public Object deserialize( byte[] bytes ) throws IOException
58 {
59 return ( ( long ) ( bytes[0] & 0xFF ) << 56 )
60 | ( ( long ) ( bytes[1] & 0xFF ) << 48 )
61 | ( ( long ) ( bytes[2] & 0xFF ) << 40 )
62 | ( ( long ) ( bytes[3] & 0xFF ) << 32 )
63 | ( ( long ) ( bytes[4] & 0xFF ) << 24 )
64 | ( ( long ) ( bytes[5] & 0xFF ) << 16 )
65 | ( ( long ) ( bytes[6] & 0xFF ) << 8 )
66 | ( ( long ) ( bytes[7] & 0xFF ) );
67 }
68 }