1 /* $Id: CodePrintStream.java 1 2010-02-24 13:03:05Z haidw $ */
4 import java.io.OutputStream;
5 import java.io.PrintStream;
8 * Class to print code that is correctly indented.
10 public class CodePrintStream extends PrintStream {
15 public CodePrintStream(OutputStream out) {
22 public CodePrintStream(OutputStream out, boolean autoFlush) {
23 super(out, autoFlush);
29 public void print(String x) {
36 public void println(String x) {
43 public void printPrefix(String x) {
44 super.print(_prefix + x);
50 public void printPrefix() {
57 public void printPrefixln(String x) {
58 super.println(_prefix + x);
64 public void printPrefixln() {
69 * Print an opening curly brace and increase the indentation.
71 public void printLeftBracket() {
78 * Decrease the indentation and print a closing curly brace.
80 public void printRightBracket() {
86 * Decrement the indentation.
88 public void prefixDec() {
89 if( _prefix.length() >= _offset.length() ) {
90 _prefix = _prefix.substring(_offset.length());
95 * Increment the indentation.
97 public void prefixInc() {
104 public static void main(String[] args) {
105 CodePrintStream ps = new CodePrintStream(System.out);
110 private static String _offset = " ";
111 private String _prefix = "";