-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializeBlockChain.java
More file actions
32 lines (28 loc) · 999 Bytes
/
Copy pathSerializeBlockChain.java
File metadata and controls
32 lines (28 loc) · 999 Bytes
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
package blockchain;
import java.io.*;
public class SerializeBlockChain {
public static void Serialize(Object object, File path) {
try {
FileOutputStream ous = new FileOutputStream(path);
BufferedOutputStream bos = new BufferedOutputStream(ous);
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(object);
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static BlockChain deserialize(File path) {
try {
FileInputStream fis = new FileInputStream(path);
BufferedInputStream bis = new BufferedInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(bis);
Object object = ois.readObject();
ois.close();
return (BlockChain) object;
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
}