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