85
|
1 package alice.jungle.persistence;
|
|
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;
|
85
|
21 private static MessagePack msgpack;
|
86
|
22 private static OutputStream out = null;
|
|
23 private static InputStream in = null;
|
|
24
|
|
25 public PersistentJournal() {
|
|
26 msgpack = new MessagePack();
|
|
27 }
|
85
|
28
|
|
29 public PersistentJournal(File file) throws FileNotFoundException {
|
|
30 out = new FileOutputStream(file, true);
|
|
31 in = new FileInputStream(file);
|
|
32 WRITER = new PersistentChangeListWriter(out);
|
|
33 READER = new PersistentChangeListReader(in);
|
|
34 msgpack = new MessagePack();
|
|
35 }
|
|
36
|
|
37 @Override
|
|
38 public ChangeListReader getReader() {
|
|
39 return READER;
|
|
40 }
|
|
41
|
|
42 @Override
|
|
43 public ChangeListWriter getWriter() {
|
|
44 return WRITER;
|
|
45 }
|
|
46
|
86
|
47 public void setOutputFile(File file) throws FileNotFoundException {
|
|
48 out = new FileOutputStream(file);
|
|
49 WRITER = new PersistentChangeListWriter(out);
|
|
50 }
|
|
51
|
|
52 public void setInputFile(File file) throws FileNotFoundException {
|
|
53 in = new FileInputStream(file);
|
|
54 READER = new PersistentChangeListReader(in);
|
|
55 }
|
|
56
|
85
|
57 public void close() throws IOException {
|
|
58 out.close();
|
|
59 in.close();
|
|
60 }
|
|
61
|
|
62 public void setOutputStream(OutputStream _out) {
|
|
63 out = _out;
|
|
64 }
|
|
65
|
|
66 public OutputStream getOutputStream() {
|
|
67 return out;
|
|
68 }
|
|
69
|
|
70 public void setInputStream(InputStream _in) {
|
|
71 in = _in;
|
|
72 }
|
|
73
|
|
74 public InputStream getInputStream() {
|
|
75 return in;
|
|
76 }
|
|
77
|
|
78 public static MessagePack getMessagePack() {
|
|
79 return msgpack;
|
|
80 }
|
|
81
|
|
82 }
|