OSDN Git Service

Alter save thread logic so that if an error happens, a message box is produced rather...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / utilities / OutStream.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.utilities;\r
21 \r
22 import java.io.DataOutputStream;\r
23 import java.io.File;\r
24 import java.io.FileNotFoundException;\r
25 import java.io.FileOutputStream;\r
26 import java.io.FilterOutputStream;\r
27 import java.io.IOException;\r
28 import java.io.OutputStream;\r
29 import java.util.ArrayList;\r
30 import java.util.List;\r
31 \r
32 import cx.fbn.nevernote.Global;\r
33 \r
34 public class OutStream extends FilterOutputStream {\r
35 \r
36         List<String> buffer;\r
37         File file;\r
38         FileOutputStream fos;\r
39         DataOutputStream dos;\r
40         \r
41         public OutStream(OutputStream out, String name) {\r
42                 super(out);\r
43                 buffer = new ArrayList<String>();\r
44                 \r
45                 file = Global.getFileManager().getLogsDirFile(name);\r
46                 try {\r
47                         fos = new FileOutputStream(file);\r
48                         dos = new DataOutputStream(fos);\r
49                 } catch (FileNotFoundException e) {}\r
50         }\r
51         \r
52         \r
53         @Override\r
54         public synchronized void write(byte b[]) throws IOException {\r
55                 String aString = new String(b);\r
56                 buffer.add(aString);\r
57                 dos.writeBytes(aString +"\n");\r
58             }\r
59 \r
60         @Override\r
61         public synchronized void write(byte b[], int off, int len) throws IOException {\r
62             String aString = new String(b , off , len);\r
63             buffer.add(aString);\r
64             dos.writeBytes(aString +"\n");\r
65         }\r
66         \r
67         public List<String> getText() {\r
68                 return buffer;\r
69         }\r
70 \r
71 }\r