-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyntaxTreeSerializer.java
39 lines (37 loc) · 1.07 KB
/
SyntaxTreeSerializer.java
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
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
public class SyntaxTreeSerializer {
public boolean serialize(String fileName, ProgramBase program) {
try {
FileOutputStream file = new FileOutputStream(fileName);
ObjectOutputStream out = new ObjectOutputStream(file);
out.writeObject(program);
out.close();
file.close();
return true;
} catch (IOException e) {
System.err.println("Serializing FAILED");
e.printStackTrace();
return false;
}
}
public ProgramBase deserialize(String fileName) {
ProgramBase program = null;
try {
FileInputStream file = new FileInputStream(fileName);
ObjectInputStream in = new ObjectInputStream(file);
program = (ProgramBase)in.readObject();
in.close();
file.close();
return program;
} catch(IOException e) {
e.printStackTrace();
} catch(ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
}