package text; import java.io.*; public class FormattedOutput { private static int INC = 4; private int indent; private int column; private PrintWriter printWriter; public FormattedOutput( File file ) throws Error { try { OutputStream outputStream = new FileOutputStream( file ); printWriter = new PrintWriter( outputStream ); } catch ( IOException exception ) { throw new Error( "Unable to open file " + file ); } } public void println() { printWriter.println(); printWriter.flush(); column = 0; } public void print( char c ) { while ( column < indent ) { printWriter.print( ' ' ); column++; } printWriter.print( c ); column++; } private void print( String s ) { int i = 0; while ( i < s.length() ) { if ( s.charAt( i ) == '%' ) { i++; switch ( s.charAt( i ) ) { case '+': indent += INC; break; case '-': indent -= INC; break; case 'n': println(); break; default: print( s.charAt( i ) ); } i++; } else { print( s.charAt( i++ ) ); } } } public void print( byte b ) { print( "" + b ); } public void print( int i ) { print( "" + i ); } public void print( double d ) { print( "" + d ); } public void print( Object s ) { print( "" + s ); } public void println( String s ) { print( s ); println(); } public void println( byte b ) { println( "" + b ); } public void println( int i ) { println( "" + i ); } public void println( double d ) { println( "" + d ); } public void println( Object s ) { println( "" + s ); } public void printStackTrace( Throwable throwable ) { printWriter.println(); throwable.printStackTrace( printWriter ); printWriter.flush(); } public void debugln() { if ( Print.DEBUG ) { println(); } } public void debugln( String s ) { if ( Print.DEBUG ) { print( s ); println(); } } public void debugln( byte b ) { debugln( "" + b ); } public void debugln( int i ) { debugln( "" + i ); } public void debugln( double d ) { debugln( "" + d ); } public void debugln( Object s ) { debugln( "" + s ); } public void debugStackTrace( Throwable throwable ) { if ( Print.DEBUG ) { printWriter.println(); throwable.printStackTrace( printWriter ); printWriter.flush(); } } }