private static String readerToString ( Reader reader ) throws IOException { StringWriter writer = new StringWriter ( ) ; try { char [ ] buffer = new char [ COPY_BUFFER_SIZE ] ; while ( true ) { int bytesRead = reader . read ( buffer ) ; if ( bytesRead == - 1 ) { break ; } else { writer . write ( buffer , 0 , bytesRead ) ; } } return writer . toString ( ) ; } finally { reader . close ( ) ; } }
Converts a Reader to a String by copying the Reader s contents into a StringWriter via a buffer .