Repository navigation
Expand file tree
/
Copy pathIssue241.java
More file actions
77 lines (67 loc) · 2.08 KB
/
Copy pathIssue241.java
File metadata and controls
77 lines (67 loc) · 2.08 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package org.mapdb;
import org.junit.Test;
import java.io.File;
import java.io.Serializable;
import java.util.Map;
public class Issue241
{
@Test
public void main()
{
DB db = getDb();
final String mapName = "map"; //$NON-NLS-1$
Map<Long, CustomClass> map = db.createTreeMap(mapName).make();
// db.createTreeMap(mapName)
// .valueSerializer(new CustomSerializer()).make();
map.put(1L, new CustomClass("aString", 1001L)); //$NON-NLS-1$
db.commit();
db.close();
db = getDb();
map = db.getTreeMap(mapName);
map.get(1L);
}
private static DB getDb()
{
final File dbFile = UtilsTest.tempDbFile();
return DBMaker.newAppendFileDB(dbFile).make();
}
private static final class CustomClass implements Serializable
{
private final String aString;
private final Long aLong;
private CustomClass(String aString, Long aLong)
{
this.aString = aString;
this.aLong = aLong;
}
private String getaString()
{
return aString;
}
private Long getaLong()
{
return aLong;
}
}
// public static final class CustomSerializer implements Serializer<CustomClass>, Serializable
// {
// @Override
// public void serialize(DataOutput out, CustomClass value) throws IOException
// {
// out.writeLong(value.getaLong());
// final byte[] stringBytes = value.getaString().getBytes();
// out.writeInt(stringBytes.length);
// out.write(stringBytes);
// }
//
// @Override
// public CustomClass deserialize(DataInput in, int available) throws IOException
// {
// final Long theLong = in.readLong();
// final int stringBytesLength = in.readInt();
// final byte[] stringBytes = new byte[stringBytesLength];
// in.readFully(stringBytes);
// return new CustomClass(new String(stringBytes), theLong);
// }
// }
}