Fixed up the DocBuffer a bit and added a basic XML writer.
[jsvc.git] / src / dolda / jsvc / next / ColumnWriter.java
CommitLineData
6e40b32e
FT
1package dolda.jsvc.next;
2
3import java.io.*;
4
5public class ColumnWriter extends FilterWriter {
6 public int line, col;
7 public boolean start = true;
8
9 public ColumnWriter(Writer out) {
10 super(out);
11 line = col = 0;
12 }
13
14 private void hc(int c) {
15 if(c == '\n') {
16 col = 0;
17 line++;
18 start = true;
19 } else if(c == '\t') {
20 col = (col - (col % 8)) + 8;
21 } else {
22 col++;
23 }
24 if(!Character.isWhitespace(c))
25 start = false;
26 }
27
28 public void write(int c) throws IOException {
29 super.write(c);
30 hc(c);
31 }
32
33 public void write(String s, int off, int len) throws IOException {
34 super.write(s, off, len);
35 for(int i = 0; i < s.length(); i++)
36 hc(s.charAt(i));
37 }
38
39 public void write(char[] b, int off, int len) throws IOException {
40 super.write(b, off, len);
41 for(int i = 0; i < len; i++, off++)
42 hc(b[off]);
43 }
44
45 public void indent(int level) throws IOException {
46 if(!start)
47 write('\n');
48 while(col < level)
49 write(' ');
50 }
51}