Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
../../../../img/srcFileCovDistChart8.png 47% of files have more coverage
24   190   19   1,5
4   71   0,79   16
16     1,19  
1    
 
  TextOutput       Line # 31 24 19 72,7% 0.72727275
 
  (6)
 
1    /* $Id: TextOutput.java,v 1.1 2008/07/26 07:55:42 m31 Exp $
2    *
3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
4    *
5    * Copyright 2000-2008, Michael Meyling <mime@qedeq.org>.
6    *
7    * "Hilbert II" is free software; you can redistribute
8    * it and/or modify it under the terms of the GNU General Public
9    * License as published by the Free Software Foundation; either
10    * version 2 of the License, or (at your option) any later version.
11    *
12    * This program is distributed in the hope that it will be useful,
13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    * GNU General Public License for more details.
16    */
17   
18    package org.qedeq.base.io;
19   
20    import java.io.IOException;
21    import java.io.OutputStream;
22    import java.io.PrintStream;
23    import java.io.UnsupportedEncodingException;
24   
25    /**
26    * Wraps a text output stream.
27    *
28    * @version $Revision: 1.1 $
29    * @author Michael Meyling
30    */
 
31    public class TextOutput {
32   
33    /** Wrapped stream. */
34    private final PrintStream output;
35   
36    /** File name. */
37    private final String name;
38   
39    /** Tab level. */
40    private StringBuffer spaces = new StringBuffer();
41   
42    /**
43    * Constructor.
44    *
45    * @param name File name.
46    * @param output Write to this output.
47    */
 
48  23 toggle public TextOutput(final String name, final OutputStream output) {
49  23 this.name = name;
50  23 try {
51  23 this.output = new PrintStream(output, false, "ISO-8859-1");
52    } catch (UnsupportedEncodingException e) {
53  0 throw new RuntimeException(e); // should never occur
54    }
55    }
56   
57    /**
58    * Print text to output.
59    *
60    * @param text Append this.
61    */
 
62  3722 toggle public void print(final String text) {
63  3722 output.print(text);
64    }
65   
66    /**
67    * Print spaces and text to output.
68    *
69    * @param text Append this.
70    */
 
71  2266 toggle public void levelPrint(final String text) {
72  2266 output.print(spaces);
73  2266 output.print(text);
74    }
75   
76    /**
77    * Print object to output.
78    *
79    * @param object Append text representation of this.
80    */
 
81  0 toggle public void print(final Object object) {
82  0 output.print(object);
83    }
84   
85    /**
86    * Print spaces text and new line to output.
87    *
88    * @param line Append this.
89    */
 
90  9790 toggle public final void println(final String line) {
91  9790 output.println(line);
92    }
93   
94    /**
95    * Print spaces, text and new line to output.
96    *
97    * @param line Append this.
98    */
 
99  4333 toggle public final void levelPrintln(final String line) {
100  4333 output.print(spaces);
101  4333 output.println(line);
102    }
103   
104    /**
105    * Print object and new line to output.
106    *
107    * @param object Append text representation of this.
108    */
 
109  140 toggle public final void println(final Object object) {
110  140 output.println(object);
111    }
112   
113    /**
114    * Print new line to output.
115    */
 
116  3264 toggle public final void println() {
117  3264 output.println();
118    }
119   
120    /**
121    * Flush output.
122    */
 
123  21 toggle public final void flush() {
124  21 output.flush();
125    }
126   
127    /**
128    * Close output.
129    */
 
130  21 toggle public final void close() {
131  21 output.close();
132    }
133   
134    /**
135    * Reset tab level to zero.
136    */
 
137  0 toggle public final void clearLevel() {
138  0 spaces.setLength(0);
139    }
140   
141    /**
142    * Decrement tab level.
143    */
 
144  3355 toggle public final void popLevel() {
145  3355 if (spaces.length() > 0) {
146  3355 spaces.setLength(spaces.length() - 2);
147    }
148    }
149   
150    /**
151    * Increment tab level.
152    */
 
153  3355 toggle public final void pushLevel() {
154  3355 spaces.append(" ");
155    }
156   
157    /**
158    * Did any error occur during output?
159    *
160    * @return Did an error occur?
161    */
 
162  21 toggle public final boolean checkError() {
163  21 return output.checkError();
164    }
165   
166    /**
167    * Get name of output file.
168    *
169    * @return File name.
170    */
 
171  18 toggle public final String getName() {
172  18 return name;
173    }
174   
175    /**
176    * Get IO exception that occurred - if any.
177    * <p>
178    * TODO mime 20070131: use something else than PrintStream to get better error support?
179    *
180    * @return Occurred IO exception. Could be <code>null</code>.
181    */
 
182  0 toggle public final IOException getError() {
183  0 if (checkError()) {
184  0 return new IOException("Writing failed.");
185    } else {
186  0 return null;
187    }
188    }
189   
190    }