105
|
1 package alice.jungle.persistent;
|
85
|
2
|
|
3 import java.io.File;
|
|
4 import java.io.FileInputStream;
|
|
5 import java.io.FileNotFoundException;
|
|
6 import java.io.FileOutputStream;
|
|
7 import java.io.IOException;
|
|
8 import java.io.InputStream;
|
|
9 import java.io.OutputStream;
|
|
10
|
|
11 import org.msgpack.MessagePack;
|
|
12
|
|
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListReader;
|
|
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter;
|
|
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Journal;
|
|
16
|
|
17 public class PersistentJournal implements Journal {
|
|
18
|
88
|
19 private static ChangeListWriter WRITER;
|
|
20 private static ChangeListReader READER;
|
116
|
21 private static MessagePack msgpack;
|
86
|
22 private static OutputStream out = null;
|
|
23 private static InputStream in = null;
|
|
24
|
116
|
25 static {
|
|
26 msgpack = new MessagePack();
|
|
27 }
|
|
28
|
86
|
29 public PersistentJournal() {
|
|
30 }
|
85
|
31
|
|
32 public PersistentJournal(File file) throws FileNotFoundException {
|
89
|
33 out = new FileOutputStream(file);
|
85
|
34 in = new FileInputStream(file);
|
|
35 WRITER = new PersistentChangeListWriter(out);
|
|
36 READER = new PersistentChangeListReader(in);
|
|
37 }
|
|
38
|
|
39 @Override
|
|
40 public ChangeListReader getReader() {
|
|
41 return READER;
|
|
42 }
|
|
43
|
|
44 @Override
|
|
45 public ChangeListWriter getWriter() {
|
|
46 return WRITER;
|
|
47 }
|
|
48
|
86
|
49 public void setOutputFile(File file) throws FileNotFoundException {
|
|
50 out = new FileOutputStream(file);
|
|
51 WRITER = new PersistentChangeListWriter(out);
|
|
52 }
|
|
53
|
|
54 public void setInputFile(File file) throws FileNotFoundException {
|
|
55 in = new FileInputStream(file);
|
|
56 READER = new PersistentChangeListReader(in);
|
|
57 }
|
|
58
|
85
|
59 public void close() throws IOException {
|
|
60 out.close();
|
|
61 in.close();
|
|
62 }
|
|
63
|
|
64 public void setOutputStream(OutputStream _out) {
|
|
65 out = _out;
|
|
66 }
|
|
67
|
|
68 public OutputStream getOutputStream() {
|
|
69 return out;
|
|
70 }
|
|
71
|
|
72 public void setInputStream(InputStream _in) {
|
|
73 in = _in;
|
|
74 }
|
|
75
|
|
76 public InputStream getInputStream() {
|
|
77 return in;
|
|
78 }
|
|
79
|
116
|
80 public static MessagePack getMsgPackInstance() {
|
85
|
81 return msgpack;
|
|
82 }
|
|
83
|
|
84 }
|