public static String indent(String s,int spaces,boolean newline){
  StringBuilder buff=new StringBuilder(s.length() + spaces);
  for (int i=0; i < s.length(); ) {
    for (int j=0; j < spaces; j++) {
      buff.append(' ');
    }
    int n=s.indexOf('\n',i);
    n=n < 0 ? s.length() : n + 1;
    buff.append(s.substring(i,n));
    i=n;
  }
  if (newline && !s.endsWith("\n")) {
    buff.append('\n');
  }
  return buff.toString();
}

public static String indent ( String s , int spaces , boolean newline ) { StringBuilder buff = new StringBuilder ( s . length ( ) + spaces ) ; for ( int i = 0 ; i < s . length ( ) ; ) { for ( int j = 0 ; j < spaces ; j ++ ) { buff . append ( ' ' ) ; } int n = s . indexOf ( '\n' , i ) ; n = n < 0 ? s . length ( ) : n + 1 ; buff . append ( s . substring ( i , n ) ) ; i = n ; } if ( newline && ! s . endsWith ( "\n" ) ) { buff . append ( '\n' ) ; } return buff . toString ( ) ; }
indents a string with spaces .
