Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mrz 27 2008 21:46:26 CET
file stats: LOC: 190   Methods: 16
NCLOC: 71   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TextOutput.java 25% 75% 81,2% 72,7%
coverage coverage
 1    /* $Id: TextOutput.java,v 1.4 2008/03/27 05:16:29 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.kernel.utility;
 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.4 $
 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  33 public TextOutput(final String name, final OutputStream output) {
 49  33 this.name = name;
 50  33 try {
 51  33 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  3758 public void print(final String text) {
 63  3758 output.print(text);
 64    }
 65   
 66    /**
 67    * Print spaces and text to output.
 68    *
 69    * @param text Append this.
 70    */
 71  2266 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 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  10648 public final void println(final String line) {
 91  10648 output.println(line);
 92    }
 93   
 94    /**
 95    * Print spaces, text and new line to output.
 96    *
 97    * @param line Append this.
 98    */
 99  4333 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  156 public final void println(final Object object) {
 110  156 output.println(object);
 111    }
 112   
 113    /**
 114    * Print new line to output.
 115    */
 116  3618 public final void println() {
 117  3618 output.println();
 118    }
 119   
 120    /**
 121    * Close output.
 122    */
 123  31 public final void flush() {
 124  31 output.flush();
 125    }
 126   
 127    /**
 128    * Close output.
 129    */
 130  31 public final void close() {
 131  31 output.close();
 132    }
 133   
 134    /**
 135    * Reset tab level to zero.
 136    */
 137  0 public final void clearLevel() {
 138  0 spaces.setLength(0);
 139    }
 140   
 141    /**
 142    * Decrement tab level.
 143    */
 144  3355 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 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  31 public final boolean checkError() {
 163  31 return output.checkError();
 164    }
 165   
 166    /**
 167    * Get name of output file.
 168    *
 169    * @return File name.
 170    */
 171  28 public final String getName() {
 172  28 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 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    }