View Javadoc

1   /*
2    * $Id: IndentWriter.java 454251 2006-10-09 02:10:57Z husted $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.sitegraph.model;
19  
20  import java.io.IOException;
21  import java.io.Writer;
22  
23  /***
24   */
25  public class IndentWriter extends Writer {
26      Writer writer;
27  
28      public IndentWriter(Writer writer) {
29          this.writer = writer;
30      }
31  
32      public void close() throws IOException {
33          writer.close();
34      }
35  
36      public void flush() throws IOException {
37          writer.flush();
38      }
39  
40      public void write(String str) throws IOException {
41          write(str, false);
42      }
43  
44      public void write(String str, boolean noIndent) throws IOException {
45          if (!noIndent) {
46              str = "    " + str;
47          }
48  
49          if (writer instanceof IndentWriter) {
50              ((IndentWriter) writer).write(str, false);
51          } else {
52              writer.write(str + "\n");
53          }
54      }
55  
56      public void write(char cbuf[], int off, int len) throws IOException {
57          writer.write(cbuf, off, len);
58      }
59  }