public static void append ( Appendable out , Object object ) throws IOException { if ( object instanceof String ) { out . append ( ( String ) object ) ; } else if ( object instanceof Object [ ] ) { out . append ( toArrayString ( ( Object [ ] ) object ) ) ; } else if ( object instanceof Map ) { out . append ( toMapString ( ( Map ) object ) ) ; } else if ( object instanceof Collection ) { out . append ( toListString ( ( Collection ) object ) ) ; } else if ( object instanceof Writable ) { Writable writable = ( Writable ) object ; Writer stringWriter = new StringBuilderWriter ( ) ; writable . writeTo ( stringWriter ) ; out . append ( stringWriter . toString ( ) ) ; } else if ( object instanceof InputStream || object instanceof Reader ) { // Copy stream to stream Reader reader ; if ( object instanceof InputStream ) { reader = new InputStreamReader ( ( InputStream ) object ) ; } else { reader = ( Reader ) object ; } char [ ] chars = new char [ 8192 ] ; int i ; while ( ( i = reader . read ( chars ) ) != - 1 ) { for ( int j = 0 ; j < i ; j ++ ) { out . append ( chars [ j ] ) ; } } reader . close ( ) ; } else { out . append ( toString ( object ) ) ; } }
Appends an object to an Appendable using Groovy s default representation for the object .