01: /*
02: * Copyright 2004,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.bsf.util;
18:
19: import java.io.OutputStream;
20: import java.io.PrintWriter;
21: import java.io.Writer;
22:
23: /**
24: * An <code>IndentWriter</code> object behaves the same as a
25: * <code>PrintWriter</code> object, with the additional capability
26: * of being able to print strings that are prepended with a specified
27: * amount of spaces.
28: *
29: * @author Matthew J. Duftler
30: */
31: public class IndentWriter extends PrintWriter {
32: /**
33: * Forwards its arguments to the <code>PrintWriter</code> constructor
34: * with the same signature.
35: */
36: public IndentWriter(OutputStream out) {
37: super (out);
38: }
39:
40: /**
41: * Forwards its arguments to the <code>PrintWriter</code> constructor
42: * with the same signature.
43: */
44: public IndentWriter(OutputStream out, boolean autoFlush) {
45: super (out, autoFlush);
46: }
47:
48: /**
49: * Forwards its arguments to the <code>PrintWriter</code> constructor
50: * with the same signature.
51: */
52: public IndentWriter(Writer out) {
53: super (out);
54: }
55:
56: /**
57: * Forwards its arguments to the <code>PrintWriter</code> constructor
58: * with the same signature.
59: */
60: public IndentWriter(Writer out, boolean autoFlush) {
61: super (out, autoFlush);
62: }
63:
64: /**
65: * Print the text (indented the specified amount) without inserting a linefeed.
66: *
67: * @param numberOfSpaces the number of spaces to indent the text.
68: * @param text the text to print.
69: */
70: public void print(int numberOfSpaces, String text) {
71: super .print(StringUtils.getChars(numberOfSpaces, ' ') + text);
72: }
73:
74: /**
75: * Print the text (indented the specified amount) and insert a linefeed.
76: *
77: * @param numberOfSpaces the number of spaces to indent the text.
78: * @param text the text to print.
79: */
80: public void println(int numberOfSpaces, String text) {
81: super .println(StringUtils.getChars(numberOfSpaces, ' ') + text);
82: }
83: }
|