forked from jankotek/mapdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaSerializer.java
More file actions
71 lines (64 loc) · 1.99 KB
/
Copy pathJavaSerializer.java
File metadata and controls
71 lines (64 loc) · 1.99 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
package org.mapdb.ser;
import org.jetbrains.annotations.Nullable;
import org.mapdb.CC;
import org.mapdb.DBException;
import org.mapdb.io.DataInput2;
import org.mapdb.io.DataInputToStream;
import org.mapdb.io.DataOutput2;
import java.io.*;
/**
* Created by jan on 2/28/16.
*/
public class JavaSerializer<E> extends DefaultGroupSerializer<E> {
@Override
public void serialize(DataOutput2 out, E value) {
ObjectOutputStream out2 = null;
try {
out2 = new ObjectOutputStream((OutputStream) out);
out2.writeObject(value);
out2.flush();
} catch (IOException e) {
throw new IOError(e);
}
}
@Override
public E deserialize(DataInput2 in) {
try {
ObjectInputStream in2 = new ObjectInputStream(new DataInputToStream(in));
return (E) in2.readObject();
} catch (ClassNotFoundException e) {
throw new DBException.SerializationError(e);
} catch (IOException e) {
throw new IOError(e);
}
}
@Nullable
@Override
public Class serializedType() {
return Object.class;
}
@Override
public Object[] valueArrayDeserialize(DataInput2 in, int size) {
try {
ObjectInputStream in2 = new ObjectInputStream(new DataInputToStream(in));
Object[] ret = (Object[]) in2.readObject();
if(CC.PARANOID && size!=valueArraySize(ret))
throw new AssertionError();
return ret;
} catch (ClassNotFoundException e) {
throw new DBException.SerializationError(e);
} catch (IOException e) {
throw new IOError(e);
}
}
@Override
public void valueArraySerialize(DataOutput2 out, Object[] vals) {
try{
ObjectOutputStream out2 = new ObjectOutputStream((OutputStream) out);
out2.writeObject(vals);
out2.flush();
} catch (IOException e) {
throw new IOError(e);
}
}
}