X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2Fnext%2FColumnWriter.java;fp=src%2Fdolda%2Fjsvc%2Fnext%2FColumnWriter.java;h=0ea5b7751644209765eab43fe22f7a1d67dcb407;hb=6e40b32ee7b4e65f600f6aeb25838d6d40e76838;hp=0000000000000000000000000000000000000000;hpb=3de0fa23dedbf36f814f1293e59aa8b8c4eef8a4;p=jsvc.git diff --git a/src/dolda/jsvc/next/ColumnWriter.java b/src/dolda/jsvc/next/ColumnWriter.java new file mode 100644 index 0000000..0ea5b77 --- /dev/null +++ b/src/dolda/jsvc/next/ColumnWriter.java @@ -0,0 +1,51 @@ +package dolda.jsvc.next; + +import java.io.*; + +public class ColumnWriter extends FilterWriter { + public int line, col; + public boolean start = true; + + public ColumnWriter(Writer out) { + super(out); + line = col = 0; + } + + private void hc(int c) { + if(c == '\n') { + col = 0; + line++; + start = true; + } else if(c == '\t') { + col = (col - (col % 8)) + 8; + } else { + col++; + } + if(!Character.isWhitespace(c)) + start = false; + } + + public void write(int c) throws IOException { + super.write(c); + hc(c); + } + + public void write(String s, int off, int len) throws IOException { + super.write(s, off, len); + for(int i = 0; i < s.length(); i++) + hc(s.charAt(i)); + } + + public void write(char[] b, int off, int len) throws IOException { + super.write(b, off, len); + for(int i = 0; i < len; i++, off++) + hc(b[off]); + } + + public void indent(int level) throws IOException { + if(!start) + write('\n'); + while(col < level) + write(' '); + } +}