Mercurial > hg > Members > nobuyasu > jungle-network
diff 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 |
line wrap: on
line diff
--- a/src/main/java/alice/jungle/persistent/PersistentJournal.java Wed Dec 25 18:48:54 2013 +0900 +++ b/src/main/java/alice/jungle/persistent/PersistentJournal.java Wed Dec 25 20:02:26 2013 +0900 @@ -16,11 +16,11 @@ public class PersistentJournal implements Journal { - private static ChangeListWriter WRITER; - private static ChangeListReader READER; + private ChangeListWriter WRITER; + private ChangeListReader READER; + private OutputStream out; + private InputStream in; private static MessagePack msgpack; - private static OutputStream out = null; - private static InputStream in = null; static { msgpack = new MessagePack(); @@ -30,7 +30,7 @@ } public PersistentJournal(File file) throws FileNotFoundException { - out = new FileOutputStream(file); + out = new FileOutputStream(file,true); in = new FileInputStream(file); WRITER = new PersistentChangeListWriter(out); READER = new PersistentChangeListReader(in); @@ -43,26 +43,29 @@ @Override public ChangeListWriter getWriter() { - return WRITER; + String timeStamp = Long.toString(System.currentTimeMillis()); + String logFileName = timeStamp + ".log"; + OutputStream outStream = null; + try { + outStream = new FileOutputStream(new File("./log/"+logFileName)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + PersistentChangeListWriter writer = new PersistentChangeListWriter(outStream); + return writer; } public void setOutputFile(File file) throws FileNotFoundException { - out = new FileOutputStream(file); - WRITER = new PersistentChangeListWriter(out); + setOutputStream(new FileOutputStream(file, true)); } public void setInputFile(File file) throws FileNotFoundException { - in = new FileInputStream(file); - READER = new PersistentChangeListReader(in); - } - - public void close() throws IOException { - out.close(); - in.close(); + setInputStream(new FileInputStream(file)); } public void setOutputStream(OutputStream _out) { out = _out; + WRITER = new PersistentChangeListWriter(out); } public OutputStream getOutputStream() { @@ -71,8 +74,9 @@ public void setInputStream(InputStream _in) { in = _in; + READER = new PersistentChangeListReader(in); } - + public InputStream getInputStream() { return in; } @@ -80,5 +84,12 @@ public static MessagePack getMsgPackInstance() { return msgpack; } + + public void close() throws IOException { + out.close(); + in.close(); + } + + }