~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/jgdi/src/com/sun/grid/jgdi/configuration/xml/IndentedPrintWriter.java

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 *
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 *
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 *
 
9
 *
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 *
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 *
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 *
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 *
 
28
 *   All Rights Reserved.
 
29
 *
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
package com.sun.grid.jgdi.configuration.xml;
 
33
 
 
34
import java.io.File;
 
35
import java.io.FileNotFoundException;
 
36
import java.io.FileWriter;
 
37
import java.io.IOException;
 
38
import java.io.OutputStream;
 
39
import java.io.PrintWriter;
 
40
import java.io.Writer;
 
41
 
 
42
/**
 
43
 * This class implements a PrintWriter with
 
44
 * indentication
 
45
 */
 
46
public class IndentedPrintWriter extends PrintWriter {
 
47
    
 
48
    private StringBuilder indent = new StringBuilder();
 
49
    
 
50
    /** this flag indicates that a indent should
 
51
     *  be added.
 
52
     *  @see #print(String)
 
53
     */
 
54
    private boolean addIndent = false;
 
55
    
 
56
    /** size of an indent step: */
 
57
    private int indentSize = 3;
 
58
    
 
59
    /**
 
60
     *  Create a new IndentedPrintWriter on an OutputStream
 
61
     *  @param  out the output stream
 
62
     */
 
63
    public IndentedPrintWriter(OutputStream out) {
 
64
        super(out);
 
65
    }
 
66
    
 
67
    /** Creates a new IndentedPrintWriter on a Writer
 
68
     *  @param writer the writer
 
69
     */
 
70
    public IndentedPrintWriter(Writer writer) {
 
71
        super(writer);
 
72
    }
 
73
    
 
74
    /** Creates a new IndentedPrintWriter on a File
 
75
     *  @param file the file
 
76
     */
 
77
    public IndentedPrintWriter(File file) throws IOException {
 
78
        super(new FileWriter(file));
 
79
    }
 
80
    
 
81
    /**
 
82
     * add an indent.
 
83
     */
 
84
    public void indent() {
 
85
        for(int i = 0; i < indentSize; i++) {
 
86
            indent.append(' ');
 
87
        }
 
88
    }
 
89
    
 
90
    /**
 
91
     * remove an indent.
 
92
     */
 
93
    public void deindent() {
 
94
        int newLen = Math.max(0,indent.length() - indentSize);
 
95
        indent.setLength(newLen);
 
96
    }
 
97
    
 
98
    
 
99
    public void println(String x) {
 
100
        print(x);
 
101
        super.println();
 
102
        addIndent = true;
 
103
    }
 
104
    
 
105
    public void print(String s) {
 
106
        if(addIndent) {
 
107
            super.print(indent);
 
108
            addIndent = false;
 
109
        }
 
110
        super.print(s);
 
111
    }
 
112
    
 
113
    public void println(Object x) {
 
114
        print(x);
 
115
        super.println();
 
116
        addIndent = true;
 
117
    }
 
118
    
 
119
    public void print(Object obj) {
 
120
        if(addIndent) {
 
121
            super.print(indent);
 
122
            addIndent = false;
 
123
        }
 
124
        super.print(obj);
 
125
    }
 
126
    
 
127
    public void println(int x) {
 
128
        print(x);
 
129
        super.println();
 
130
        addIndent = true;
 
131
    }
 
132
    
 
133
    public void print(int i) {
 
134
        if(addIndent) {
 
135
            super.print(indent);
 
136
            addIndent = false;
 
137
        }
 
138
        super.print(i);
 
139
    }
 
140
    
 
141
    public void print(boolean b) {
 
142
        if(addIndent) {
 
143
            super.print(indent);
 
144
            addIndent = false;
 
145
        }
 
146
        super.print(b);
 
147
    }
 
148
    
 
149
    public void println(boolean x) {
 
150
        print(x);
 
151
        super.println();
 
152
        addIndent = true;
 
153
    }
 
154
    
 
155
    public void println(long x) {
 
156
        print(x);
 
157
        super.println();
 
158
        addIndent = true;
 
159
    }
 
160
    
 
161
    public void print(long l) {
 
162
        if(addIndent) {
 
163
            super.print(indent);
 
164
            addIndent = false;
 
165
        }
 
166
        super.print(l);
 
167
    }
 
168
    
 
169
    public void println(double x) {
 
170
        print(x);
 
171
        super.println();
 
172
        addIndent = true;
 
173
    }
 
174
    
 
175
    public void println(char[] x) {
 
176
        print(x);
 
177
        super.println();
 
178
        addIndent = true;
 
179
    }
 
180
    
 
181
    public void print(char[] s) {
 
182
        if(addIndent) {
 
183
            super.print(indent);
 
184
            addIndent = false;
 
185
        }
 
186
        super.print(s);
 
187
    }
 
188
    
 
189
    public void print(double d) {
 
190
        if(addIndent) {
 
191
            super.print(indent);
 
192
            addIndent = false;
 
193
        }
 
194
        super.print(d);
 
195
    }
 
196
    
 
197
    public void println(char x) {
 
198
        print(x);
 
199
        super.println();
 
200
        addIndent = true;
 
201
    }
 
202
    
 
203
    public void print(char c) {
 
204
        if(addIndent) {
 
205
            super.print(indent);
 
206
            addIndent = false;
 
207
        }
 
208
        super.print(c);
 
209
    }
 
210
    
 
211
    
 
212
    public void println(float x) {
 
213
        print(x);
 
214
        super.println();
 
215
        addIndent = true;
 
216
    }
 
217
    
 
218
    public void print(float f) {
 
219
        if(addIndent) {
 
220
            super.print(indent);
 
221
            addIndent = false;
 
222
        }
 
223
        super.print(f);
 
224
    }
 
225
    
 
226
    
 
227
    public void println() {
 
228
        super.println();
 
229
        addIndent = true;
 
230
    }
 
231
    
 
232
    public int getIndentSize() {
 
233
        return indentSize;
 
234
    }
 
235
    
 
236
    public void setIndentSize(int indentSize) {
 
237
        this.indentSize = indentSize;
 
238
    }
 
239
    
 
240
}