Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mai 10 2007 03:16:40 CEST
file stats: LOC: 196   Methods: 17
NCLOC: 70   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TextOutput.java 25% 70,8% 76,5% 68,9%
coverage coverage
 1    /* $Id: TextOutput.java,v 1.3 2007/05/10 00:37:50 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2007, 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.kernel.utility;
 19   
 20    import java.io.IOException;
 21    import java.io.OutputStream;
 22    import java.io.PrintStream;
 23   
 24    /**
 25    * Wraps a text output stream.
 26    *
 27    * @version $Revision: 1.3 $
 28    * @author Michael Meyling
 29    */
 30    public class TextOutput {
 31   
 32    /** Wrapped stream. */
 33    private final PrintStream output;
 34   
 35    /** File name. */
 36    private final String name;
 37   
 38    /** Tab level. */
 39    private StringBuffer spaces = new StringBuffer();
 40   
 41    /**
 42    * Constructor.
 43    *
 44    * @param name File name.
 45    * @param output Write to this output.
 46    */
 47  0 public TextOutput(final String name, final PrintStream output) {
 48  0 this.name = name;
 49  0 this.output = output;
 50    }
 51   
 52    /**
 53    * Constructor.
 54    *
 55    * @param name File name.
 56    * @param output Write to this output.
 57    */
 58  16 public TextOutput(final String name, final OutputStream output) {
 59  16 this.name = name;
 60  16 this.output = new PrintStream(output);
 61    }
 62   
 63    /**
 64    * Print text to output.
 65    *
 66    * @param text Append this.
 67    */
 68  3412 public void print(final String text) {
 69  3412 output.print(text);
 70    }
 71   
 72    /**
 73    * Print spaces and text to output.
 74    *
 75    * @param text Append this.
 76    */
 77  2268 public void levelPrint(final String text) {
 78  2268 output.print(spaces);
 79  2268 output.print(text);
 80    }
 81   
 82    /**
 83    * Print object to output.
 84    *
 85    * @param object Append text representation of this.
 86    */
 87  0 public void print(final Object object) {
 88  0 output.print(object);
 89    }
 90   
 91    /**
 92    * Print spaces text and new line to output.
 93    *
 94    * @param line Append this.
 95    */
 96  6851 public final void println(final String line) {
 97  6851 output.println(line);
 98    }
 99   
 100    /**
 101    * Print spaces, text and new line to output.
 102    *
 103    * @param line Append this.
 104    */
 105  4337 public final void levelPrintln(final String line) {
 106  4337 output.print(spaces);
 107  4337 output.println(line);
 108    }
 109   
 110    /**
 111    * Print object and new line to output.
 112    *
 113    * @param object Append text representation of this.
 114    */
 115  83 public final void println(final Object object) {
 116  83 output.println(object);
 117    }
 118   
 119    /**
 120    * Print new line to output.
 121    */
 122  1980 public final void println() {
 123  1980 output.println();
 124    }
 125   
 126    /**
 127    * Close output.
 128    */
 129  14 public final void flush() {
 130  14 output.flush();
 131    }
 132   
 133    /**
 134    * Close output.
 135    */
 136  14 public final void close() {
 137  14 output.close();
 138    }
 139   
 140    /**
 141    * Reset tab level to zero.
 142    */
 143  0 public final void clearLevel() {
 144  0 spaces.setLength(0);
 145    }
 146   
 147    /**
 148    * Decrement tab level.
 149    */
 150  3358 public final void popLevel() {
 151  3358 if (spaces.length() > 0) {
 152  3358 spaces.setLength(spaces.length() - 2);
 153    }
 154    }
 155   
 156    /**
 157    * Increment tab level.
 158    */
 159  3358 public final void pushLevel() {
 160  3358 spaces.append(" ");
 161    }
 162   
 163    /**
 164    * Did any error occur during output?
 165    *
 166    * @return Did an error occur?
 167    */
 168  14 public final boolean checkError() {
 169  14 return output.checkError();
 170    }
 171   
 172    /**
 173    * Get name of output file.
 174    *
 175    * @return File name.
 176    */
 177  11 public final String getName() {
 178  11 return name;
 179    }
 180   
 181    /**
 182    * Get IO exception that occurred - if any.
 183    * <p>
 184    * TODO mime 20070131: use something else than PrintStream to get better error support?
 185    *
 186    * @return Occurred IO exception. Could be <code>null</code>.
 187    */
 188  0 public final IOException getError() {
 189  0 if (checkError()) {
 190  0 return new IOException("Writing failed.");
 191    } else {
 192  0 return null;
 193    }
 194    }
 195   
 196    }