Mercurial > hg > Members > nobuyasu > jungle-network
comparison src/main/java/alice/jungle/persistent/PersistentJournal.java @ 105:f9e29a52efd3
Move some files
author | one |
---|---|
date | Tue, 26 Nov 2013 06:43:10 +0900 |
parents | src/alice/jungle/persistence/PersistentJournal.java@f3f89613c7e3 |
children | 3f9c6ab43461 |
comparison
equal
deleted
inserted
replaced
104:03bf62bb699e | 105:f9e29a52efd3 |
---|---|
1 package alice.jungle.persistent; | |
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 | |
19 private static ChangeListWriter WRITER; | |
20 private static ChangeListReader READER; | |
21 private static MessagePack msgpack; | |
22 private static OutputStream out = null; | |
23 private static InputStream in = null; | |
24 | |
25 public PersistentJournal() { | |
26 msgpack = new MessagePack(); | |
27 } | |
28 | |
29 public PersistentJournal(File file) throws FileNotFoundException { | |
30 out = new FileOutputStream(file); | |
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 | |
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 | |
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 } |