1 45 package org.exolab.jms.plugins.proxygen; 46 47 import java.io.BufferedWriter ; 48 import java.io.IOException ; 49 import java.io.Writer ; 50 51 52 58 public class SourceWriter extends BufferedWriter { 59 60 63 private int _indent = 0; 64 65 68 private final int _spaces = 4; 69 70 73 private boolean _startOfLine = true; 74 75 76 81 public SourceWriter(Writer writer) { 82 super(writer); 83 } 84 85 88 public void incIndent() { 89 ++_indent; 90 } 91 92 95 public void decIndent() { 96 --_indent; 97 } 98 99 105 public void write(int ch) throws IOException { 106 indent(); 107 super.write(ch); 108 } 109 110 118 public void write(char[] buffer, int offset, int length) 119 throws IOException { 120 indent(); 121 super.write(buffer, offset, length); 122 } 123 124 132 public void write(String string, int offset, int length) 133 throws IOException { 134 indent(); 135 super.write(string, offset, length); 136 } 137 138 143 public void writeln() throws IOException { 144 newLine(); 145 } 146 147 153 public void writeln(String string) throws IOException { 154 write(string); 155 newLine(); 156 } 157 158 163 public void writelnInc() throws IOException { 164 newLine(); 165 incIndent(); 166 } 167 168 174 public void writelnInc(String string) throws IOException { 175 writeln(string); 176 incIndent(); 177 } 178 179 184 public void writelnDec() throws IOException { 185 newLine(); 186 decIndent(); 187 } 188 189 195 public void writelnDec(String string) throws IOException { 196 writeln(string); 197 decIndent(); 198 } 199 200 205 public void newLine() throws IOException { 206 super.newLine(); 207 _startOfLine = true; 208 } 209 210 215 protected void indent() throws IOException { 216 if (_startOfLine) { 217 int count = _indent * _spaces; 218 for (int i = 0; i < count; ++i) { 219 super.write(' '); 220 } 221 _startOfLine = false; 222 } 223 } 224 225 } 226 | Popular Tags |