OSDN Git Service

c2e668ca5ea4a956806d6e481a3de50015df0b59
[pf3gnuchains/gcc-fork.git] / libjava / gnu / java / rmi / rmic / TabbedWriter.java
1 /*
2   Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10  
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
20
21 As a special exception, if you link this library with other files to
22 produce an executable, this library does not by itself cause the
23 resulting executable to be covered by the GNU General Public License.
24 This exception does not however invalidate any other reasons why the
25 executable file might be covered by the GNU General Public License.
26  */
27
28 package gnu.java.rmi.rmic;
29
30 import java.io.FilterWriter;
31 import java.io.Writer;
32 import java.io.IOException;
33
34 public class TabbedWriter
35         extends FilterWriter {
36
37 private static final String defaultTabstring = "    ";
38 private char[] tabstring; 
39 private int tabs;
40
41 public TabbedWriter(Writer o) {
42         this(o, defaultTabstring);
43 }
44
45 public TabbedWriter(Writer o, String str) {
46         super(o);
47         tabs = 0;
48         tabstring = str.toCharArray();
49 }
50
51 public void write(int c) throws IOException {
52         out.write(c);
53         if (c == '\n') {
54                 for (int i = 0; i < tabs; i++) {
55                         out.write(tabstring, 0, tabstring.length);
56                 }
57         }
58 }
59
60 public void write(char cbuf[], int off, int len) throws IOException {
61         for (int i = 0; i < len; i++) {
62                 write((int)cbuf[i+off]);
63         }
64 }
65
66 public void write(String str, int off, int len) throws IOException {
67         write(str.toCharArray(), off, len);
68 }
69
70 public void unindent() throws IOException {
71         unindent(1);
72 }
73
74 public void unindent(int nr) throws IOException {
75         indent(-nr);
76 }
77
78 public void indent() throws IOException {
79         indent(1);
80 }
81
82 public void indent(int nr) throws IOException {
83         tabs += nr;
84         if (tabs < 0) {
85                 tabs = 0;
86         }
87         write((int)'\n');
88 }
89
90 }