org.metasyntactic.io
Class IndentingPrintStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--java.io.FilterOutputStream
              |
              +--java.io.PrintStream
                    |
                    +--org.metasyntactic.io.IndentingPrintStream

public class IndentingPrintStream
extends java.io.PrintStream

An implementation of print stream created with the intention of allowing programmers to easily "write" code while not keeping track of the annoying problem of indentation everytime the print out a line. Note! This behaviour is only accomplished as long as you use the println() methods and don't put "\n" in your strings.

The class also allows for automatic indenting and deindenting of code blocks. Simply tell the class which strings start and end your code blocks and the indenting/deindenting will be done automatically.

For example:

 out = new IndentingPrintStream(Some_Output_Stream, false,
                                "\t", "{", "}");

 out.println("public class foo {");
 out.println("public static void bar() {");
 out.println("if (1 + 1 == 2) {");
 out.println("System.out.println(\"Java works\");");
 out.println("} else {");
 out.println("System.out.println(\"Uh oh!\");");
 out.println("}");
 out.println("}");
 out.println("}");

 will print to the output stream:

 public class foo {
     public static void bar() {
         if (1 + 1 == 2) {
             System.out.println("Java works");
         } else {
             System.out.println("Uh oh!");
         }
     }
 }
 

 Note!  This is not a perfect system and a few
 rules/concessions must be dealt with.
 
First: as stated above. Do not use \n unles you are trying to circumvent this system.
Second: if you are using automatic indenting, you can only have max 1 indenter and 1 deindenter per line. And the indenter must occur at the very end of the string, and the deindenter has to occur at the very beginning. This means that you cannot type {{ and have it know that you want to indents.


Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
IndentingPrintStream(java.io.OutputStream out)
           
IndentingPrintStream(java.io.OutputStream out, boolean autoFlush)
           
IndentingPrintStream(java.io.OutputStream out, boolean autoFlush, java.lang.String indentString)
           
IndentingPrintStream(java.io.OutputStream out, boolean autoFlush, java.lang.String indentString, java.lang.String[] autoIndentStrings, java.lang.String[] autoDeIndentStrings)
           
IndentingPrintStream(java.io.OutputStream out, boolean autoFlush, java.lang.String indentString, java.lang.String autoIndentString, java.lang.String autoDeIndentString)
           
 
Method Summary
 java.lang.String decreaseIndent()
           
 java.lang.String increaseIndent()
           
static void main(java.lang.String[] args)
           
 void print(java.lang.Object o)
           
 void print(java.lang.String s)
           
 void println()
           
 
Methods inherited from class java.io.PrintStream
checkError, close, flush, print, print, print, print, print, print, print, println, println, println, println, println, println, println, println, println, setError, write, write
 
Methods inherited from class java.io.FilterOutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndentingPrintStream

public IndentingPrintStream(java.io.OutputStream out)

IndentingPrintStream

public IndentingPrintStream(java.io.OutputStream out,
                            boolean autoFlush)

IndentingPrintStream

public IndentingPrintStream(java.io.OutputStream out,
                            boolean autoFlush,
                            java.lang.String indentString)

IndentingPrintStream

public IndentingPrintStream(java.io.OutputStream out,
                            boolean autoFlush,
                            java.lang.String indentString,
                            java.lang.String autoIndentString,
                            java.lang.String autoDeIndentString)

IndentingPrintStream

public IndentingPrintStream(java.io.OutputStream out,
                            boolean autoFlush,
                            java.lang.String indentString,
                            java.lang.String[] autoIndentStrings,
                            java.lang.String[] autoDeIndentStrings)
Method Detail

increaseIndent

public java.lang.String increaseIndent()

decreaseIndent

public java.lang.String decreaseIndent()

print

public void print(java.lang.Object o)
Overrides:
print in class java.io.PrintStream

print

public void print(java.lang.String s)
Overrides:
print in class java.io.PrintStream

println

public void println()
Overrides:
println in class java.io.PrintStream

main

public static void main(java.lang.String[] args)