Mercurial > hg > Members > nobuyasu > jungle-network
annotate src/main/java/alice/jungle/persistent/PersistentJournal.java @ 158:cd4d64249931
minor fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 12 Jul 2014 15:58:48 +0900 |
parents | 2e8034524259 |
children | 54d68cda84c4 |
rev | line source |
---|---|
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 | |
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListReader; | |
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; | |
14 | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
15 public class PersistentJournal implements NetworkJournal { |
85 | 16 |
158 | 17 // private ChangeListWriter WRITER; |
118
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
18 private ChangeListReader READER; |
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
19 private OutputStream out; |
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
20 private InputStream in; |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
21 |
86 | 22 public PersistentJournal() { |
23 } | |
85 | 24 |
25 public PersistentJournal(File file) throws FileNotFoundException { | |
118
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
26 out = new FileOutputStream(file,true); |
85 | 27 in = new FileInputStream(file); |
158 | 28 // WRITER = new PersistentChangeListWriter(out); |
85 | 29 READER = new PersistentChangeListReader(in); |
30 } | |
31 | |
32 @Override | |
33 public ChangeListReader getReader() { | |
34 return READER; | |
35 } | |
36 | |
37 @Override | |
38 public ChangeListWriter getWriter() { | |
118
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
39 String timeStamp = Long.toString(System.currentTimeMillis()); |
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
40 String logFileName = timeStamp + ".log"; |
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
41 OutputStream outStream = null; |
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
42 try { |
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
43 outStream = new FileOutputStream(new File("./log/"+logFileName)); |
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
44 } catch (FileNotFoundException e) { |
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
45 e.printStackTrace(); |
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
46 } |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
47 ChangeListWriter writer = new PersistentChangeListWriter(outStream); |
118
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
48 return writer; |
85 | 49 } |
50 | |
86 | 51 public void setOutputFile(File file) throws FileNotFoundException { |
118
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
52 setOutputStream(new FileOutputStream(file, true)); |
86 | 53 } |
54 | |
55 public void setInputFile(File file) throws FileNotFoundException { | |
118
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
56 setInputStream(new FileInputStream(file)); |
85 | 57 } |
58 | |
59 public void setOutputStream(OutputStream _out) { | |
60 out = _out; | |
158 | 61 // WRITER = new PersistentChangeListWriter(out); |
85 | 62 } |
63 | |
64 public OutputStream getOutputStream() { | |
65 return out; | |
66 } | |
67 | |
68 public void setInputStream(InputStream _in) { | |
69 in = _in; | |
118
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
70 READER = new PersistentChangeListReader(in); |
85 | 71 } |
118
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
72 |
85 | 73 public InputStream getInputStream() { |
74 return in; | |
75 } | |
76 | |
118
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
77 public void close() throws IOException { |
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
78 out.close(); |
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
79 in.close(); |
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
116
diff
changeset
|
80 } |
85 | 81 } |