EMMA Coverage Report (generated Fri Feb 14 08:28:31 UTC 2014)
[all classes][org.qedeq.base.io]

COVERAGE SUMMARY FOR SOURCE FILE [TextOutput.java]

nameclass, %method, %block, %line, %
TextOutput.java100% (1/1)100% (9/9)100% (73/73)100% (25/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TextOutput100% (1/1)100% (9/9)100% (73/73)100% (25/25)
TextOutput (String, OutputStream, String): void 100% (1/1)100% (21/21)100% (7/7)
TextOutput (String, PrintStream): void 100% (1/1)100% (9/9)100% (4/4)
append (String): void 100% (1/1)100% (13/13)100% (3/3)
checkError (): boolean 100% (1/1)100% (4/4)100% (1/1)
close (): void 100% (1/1)100% (4/4)100% (2/2)
flush (): void 100% (1/1)100% (6/6)100% (3/3)
getError (): IOException 100% (1/1)100% (10/10)100% (3/3)
getName (): String 100% (1/1)100% (3/3)100% (1/1)
getPosition (): long 100% (1/1)100% (3/3)100% (1/1)

1/* This file is part of the project "Hilbert II" - http://www.qedeq.org
2 *
3 * Copyright 2000-2014,  Michael Meyling <mime@qedeq.org>.
4 *
5 * "Hilbert II" is free software; you can redistribute
6 * it and/or modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15 
16package org.qedeq.base.io;
17 
18import java.io.IOException;
19import java.io.OutputStream;
20import java.io.PrintStream;
21import java.io.UnsupportedEncodingException;
22 
23 
24/**
25 * Wraps a text output stream.
26 *
27 * @author  Michael Meyling
28 */
29public class TextOutput extends AbstractOutput {
30 
31    /** Wrapped stream. */
32    private final PrintStream output;
33 
34    /** File name. */
35    private final String name;
36 
37    /** Number of characters written. */
38    private long position;
39 
40    /**
41     * Constructor.
42     *
43     * @param   name        File name.
44     * @param   output      Write to this output. Must have the correct encoding.
45     */
46    public TextOutput(final String name, final PrintStream output) {
47        super();
48        this.name = name;
49        this.output = output;
50    }
51 
52    /**
53     * Constructor.
54     *
55     * @param   name        File name.
56     * @param   output      Write to this output.
57     * @param   encoding    Use this encoding.
58     */
59    public TextOutput(final String name, final OutputStream output, final String encoding) {
60        super();
61        this.name = name;
62        try {
63            this.output = new PrintStream(output, false, encoding);
64        } catch (UnsupportedEncodingException e) {
65            throw new RuntimeException(e);
66        }
67    }
68 
69    /**
70     * Flush output.
71     */
72    public final void flush() {
73        super.flush();
74        output.flush();
75    }
76 
77    /**
78     * Close output.
79     */
80    public final void close() {
81        output.close();
82    }
83 
84    /**
85     * Did any error occur during output?
86     *
87     * @return  Did an error occur?
88     */
89    public final boolean checkError() {
90        return output.checkError();
91    }
92 
93    /**
94     * Get name of output file.
95     *
96     * @return  File name.
97     */
98    public final String getName() {
99        return name;
100    }
101 
102    /**
103     * Get IO exception that occurred - if any.
104     * <p>
105     * LATER mime 20070131: use something else than PrintStream to get better error support?
106     *
107     * @return  Occurred IO exception. Could be <code>null</code>.
108     */
109    public final IOException getError() {
110        if (checkError()) {
111            return new IOException("Writing failed.");
112        } else {
113            return null;
114        }
115    }
116 
117    public void append(final String text) {
118        position += text.length();
119        output.print(text);
120    }
121 
122    public long getPosition() {
123        return position;
124    }
125 
126}

[all classes][org.qedeq.base.io]
EMMA 2.1.5320 (stable) (C) Vladimir Roubtsov