Mercurial > hg > Members > nobuyasu > jungle-network
comparison src/main/java/alice/jungle/persistent/PersistentJournal.java @ 118:f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
author | one |
---|---|
date | Wed, 25 Dec 2013 20:02:26 +0900 |
parents | 895ab2907db3 |
children | 2e8034524259 |
comparison
equal
deleted
inserted
replaced
117:24fdf5126f4d | 118:f64ff5bd66f5 |
---|---|
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; | 14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; |
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Journal; | 15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Journal; |
16 | 16 |
17 public class PersistentJournal implements Journal { | 17 public class PersistentJournal implements Journal { |
18 | 18 |
19 private static ChangeListWriter WRITER; | 19 private ChangeListWriter WRITER; |
20 private static ChangeListReader READER; | 20 private ChangeListReader READER; |
21 private OutputStream out; | |
22 private InputStream in; | |
21 private static MessagePack msgpack; | 23 private static MessagePack msgpack; |
22 private static OutputStream out = null; | |
23 private static InputStream in = null; | |
24 | 24 |
25 static { | 25 static { |
26 msgpack = new MessagePack(); | 26 msgpack = new MessagePack(); |
27 } | 27 } |
28 | 28 |
29 public PersistentJournal() { | 29 public PersistentJournal() { |
30 } | 30 } |
31 | 31 |
32 public PersistentJournal(File file) throws FileNotFoundException { | 32 public PersistentJournal(File file) throws FileNotFoundException { |
33 out = new FileOutputStream(file); | 33 out = new FileOutputStream(file,true); |
34 in = new FileInputStream(file); | 34 in = new FileInputStream(file); |
35 WRITER = new PersistentChangeListWriter(out); | 35 WRITER = new PersistentChangeListWriter(out); |
36 READER = new PersistentChangeListReader(in); | 36 READER = new PersistentChangeListReader(in); |
37 } | 37 } |
38 | 38 |
41 return READER; | 41 return READER; |
42 } | 42 } |
43 | 43 |
44 @Override | 44 @Override |
45 public ChangeListWriter getWriter() { | 45 public ChangeListWriter getWriter() { |
46 return WRITER; | 46 String timeStamp = Long.toString(System.currentTimeMillis()); |
47 String logFileName = timeStamp + ".log"; | |
48 OutputStream outStream = null; | |
49 try { | |
50 outStream = new FileOutputStream(new File("./log/"+logFileName)); | |
51 } catch (FileNotFoundException e) { | |
52 e.printStackTrace(); | |
53 } | |
54 PersistentChangeListWriter writer = new PersistentChangeListWriter(outStream); | |
55 return writer; | |
47 } | 56 } |
48 | 57 |
49 public void setOutputFile(File file) throws FileNotFoundException { | 58 public void setOutputFile(File file) throws FileNotFoundException { |
50 out = new FileOutputStream(file); | 59 setOutputStream(new FileOutputStream(file, true)); |
51 WRITER = new PersistentChangeListWriter(out); | |
52 } | 60 } |
53 | 61 |
54 public void setInputFile(File file) throws FileNotFoundException { | 62 public void setInputFile(File file) throws FileNotFoundException { |
55 in = new FileInputStream(file); | 63 setInputStream(new FileInputStream(file)); |
56 READER = new PersistentChangeListReader(in); | |
57 } | |
58 | |
59 public void close() throws IOException { | |
60 out.close(); | |
61 in.close(); | |
62 } | 64 } |
63 | 65 |
64 public void setOutputStream(OutputStream _out) { | 66 public void setOutputStream(OutputStream _out) { |
65 out = _out; | 67 out = _out; |
68 WRITER = new PersistentChangeListWriter(out); | |
66 } | 69 } |
67 | 70 |
68 public OutputStream getOutputStream() { | 71 public OutputStream getOutputStream() { |
69 return out; | 72 return out; |
70 } | 73 } |
71 | 74 |
72 public void setInputStream(InputStream _in) { | 75 public void setInputStream(InputStream _in) { |
73 in = _in; | 76 in = _in; |
77 READER = new PersistentChangeListReader(in); | |
74 } | 78 } |
75 | 79 |
76 public InputStream getInputStream() { | 80 public InputStream getInputStream() { |
77 return in; | 81 return in; |
78 } | 82 } |
79 | 83 |
80 public static MessagePack getMsgPackInstance() { | 84 public static MessagePack getMsgPackInstance() { |
81 return msgpack; | 85 return msgpack; |
82 } | 86 } |
87 | |
88 public void close() throws IOException { | |
89 out.close(); | |
90 in.close(); | |
91 } | |
92 | |
93 | |
83 | 94 |
84 } | 95 } |