01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10: package de.uka.ilkd.key.util.pp;
11:
12: import java.io.IOException;
13: import java.io.Writer;
14:
15: /** A {@link Backend} which writes all output to a java.io.Writer.
16: * The {@link #mark(Object o)} method does nothing in this implementation.
17: * There is a method {@link #count()} which returns the number of characters
18: * written by this so far.
19: */
20:
21: public class WriterBackend implements Backend {
22:
23: protected Writer out;
24: protected int lineWidth;
25: protected int count = 0;
26:
27: public WriterBackend(Writer w, int lineWidth) {
28: this .out = w;
29: this .lineWidth = lineWidth;
30: }
31:
32: /** Append a String <code>s</code> to the output. <code>s</code>
33: * contains no newlines. */
34: public void print(String s) throws IOException {
35: out.write(s);
36: count += measure(s);
37: }
38:
39: /** Start a new line. */
40: public void newLine() throws IOException {
41: out.write('\n');
42: count++;
43: }
44:
45: /** Closes this backend */
46: public void close() throws IOException {
47: out.close();
48: }
49:
50: /** Flushes any buffered output */
51: public void flush() throws IOException {
52: out.flush();
53: }
54:
55: /** Gets called to record a <code>mark()</code> call in the input. */
56: public void mark(Object o) {
57: return;
58: }
59:
60: /** Returns the number of characters written through this backend.*/
61: public int count() {
62: return count;
63: }
64:
65: /** Returns the available space per line */
66: public int lineWidth() {
67: return lineWidth;
68: }
69:
70: /** Returns the space required to print the String <code>s</code> */
71: public int measure(String s) {
72: return s.length();
73: }
74:
75: }
|