Clover coverage report - brownies library - 1.0-beta-1 Coverage timestamp: 月 8 16 2004 17:14:42 GMT+09:00 FRAMES NO FRAMES |
file stats: | LOC: | 145 |  | Methods: | 13
| NCLOC: | 79 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
TextFile.java | 100% | 37.9% | 23.1% | 36.4% |

1 |  |
     /*
2 |  |
      * Joey and its relative products are published under the terms
3 |  |
      * of the Apache Software License.
4 |  |
      */
5 |  |
     package org.asyrinx.brownie.core.io;
6 |  |
7 |  |
     import java.io.BufferedOutputStream;
8 |  |
     import java.io.BufferedReader;
9 |  |
     import java.io.File;
10 |  |
     import java.io.FileInputStream;
11 |  |
     import java.io.FileNotFoundException;
12 |  |
     import java.io.FileOutputStream;
13 |  |
     import java.io.IOException;
14 |  |
     import java.io.InputStream;
15 |  |
     import java.io.InputStreamReader;
16 |  |
     import java.io.OutputStream;
17 |  |
     import java.io.OutputStreamWriter;
18 |  |
     import java.io.StringReader;
19 |  |
20 |  |
     import org.asyrinx.brownie.core.lang.StringUtils;
21 |  |
22 |  |
     /**
23 |  |
      * テキストファイルを表すクラスです。
24 |  |
      *
25 |  |
      * @author Akima
26 |  |
      */
27 |  |
     public class TextFile extends File {
28 |  |
29 |  |
         /**
30 |  |
          * Constructor for FileContent.
31 |  |
          *
32 |  |
          * @param pathname
33 |  |
          */
34 | 6 |
         public TextFile(String pathname) {
35 | 6 |
             super(pathname);
36 |  |
         }
37 |  |
38 |  |
         /**
39 |  |
          * Constructor for FileContent.
40 |  |
          *
41 |  |
          * @param parent
42 |  |
          * @param child
43 |  |
          */
44 | 0 |
         public TextFile(File parent, String child) {
45 | 0 |
             super(parent, child);
46 |  |
         }
47 |  |
48 |  |
         /**
49 |  |
          * Constructor for FileContent.
50 |  |
          *
51 |  |
          * @param pathname
52 |  |
          */
53 | 0 |
         public TextFile(String pathname, String text) {
54 | 0 |
             super(pathname);
55 | 0 |
             this.text = text;
56 |  |
         }
57 |  |
58 |  |
         /**
59 |  |
          * Constructor for FileContent.
60 |  |
          *
61 |  |
          * @param parent
62 |  |
          * @param child
63 |  |
          */
64 | 0 |
         public TextFile(String parent, String child, String text) {
65 | 0 |
             super(parent, child);
66 | 0 |
             this.text = text;
67 |  |
         }
68 |  |
69 |  |
         /**
70 |  |
          * Constructor for FileContent.
71 |  |
          *
72 |  |
          * @param parent
73 |  |
          * @param child
74 |  |
          */
75 | 0 |
         public TextFile(File parent, String child, String text) {
76 | 0 |
             super(parent, child);
77 | 0 |
             this.text = text;
78 |  |
         }
79 |  |
80 |  |
         private String text = null;
81 |  |
82 |  |
         /**
83 |  |
          * Returns the text.
84 |  |
          *
85 |  |
          * @return String
86 |  |
          */
87 | 5 |
         public String getText() {
88 | 5 |
             return text;
89 |  |
         }
90 |  |
91 |  |
         /**
92 |  |
          * Sets the text.
93 |  |
          *
94 |  |
          * @param text
95 |  |
          *            The text to set
96 |  |
          */
97 | 0 |
         public void setText(String text) {
98 | 0 |
             this.text = text;
99 |  |
         }
100 |  |
101 | 0 |
         public void load() throws FileNotFoundException, IOException {
102 | 0 |
             load(new FileInputStream(this));
103 |  |
         }
104 |  |
105 | 5 |
         public void load(InputStream source) throws IOException {
106 | 5 |
             BufferedReader reader = new BufferedReader(
107 |  |
                     new InputStreamReader(source));
108 | 5 |
             try {
109 | 5 |
                 StringBuffer result = new StringBuffer();
110 | 5 |
                 int c = reader.read();
111 | 5 |
                 while (c > 0) {
112 | 82 |
                     result.append((char) c);
113 | 82 |
                     c = reader.read();
114 |  |
                 }
115 | 5 |
                 text = result.toString();
116 |  |
             } finally {
117 | 5 |
                 reader.close();
118 |  |
             }
119 |  |
         }
120 |  |
121 | 0 |
         public void save() throws IOException {
122 | 0 |
             BufferedOutputStream bos = new BufferedOutputStream(
123 |  |
                     new FileOutputStream(this));
124 | 0 |
             try {
125 | 0 |
                 save(bos);
126 |  |
             } finally {
127 | 0 |
                 bos.close();
128 |  |
             }
129 |  |
         }
130 |  |
131 | 0 |
         public void save(OutputStream dest) throws IOException {
132 | 0 |
             StringReader reader = new StringReader(text);
133 | 0 |
             StreamUtils.copy(reader, new OutputStreamWriter(dest));
134 | 0 |
             reader.close();
135 |  |
         }
136 |  |
137 | 0 |
         public boolean compare(InputStream target) throws IOException {
138 | 0 |
             return StreamUtils.compare(new StringReader(text),
139 |  |
                     new InputStreamReader(target));
140 |  |
         }
141 |  |
142 | 0 |
         public boolean compare(String target) {
143 | 0 |
             return StringUtils.compare(this.text, target);
144 |  |
         }
145 |  |
     }