public static String readerToString(Reader reader) throws IOException {
        assert reader != null;
        
        StringWriter strWriter = new StringWriter();
        char[] buffer = new char[65536];
        int charsRead = reader.read(buffer);
        while (charsRead > 0) {
            strWriter.write(buffer, 0, charsRead);
            charsRead = reader.read(buffer);
        }
        reader.close();
        return strWriter.toString();
    }
public static String readerToString ( Reader reader ) throws IOException { assert reader != null ; StringWriter strWriter = new StringWriter ( ) ; char [ ] buffer = new char [ 65536 ] ; int charsRead = reader . read ( buffer ) ; while ( charsRead > 0 ) { strWriter . write ( buffer , 0 , charsRead ) ; charsRead = reader . read ( buffer ) ; } reader . close ( ) ; return strWriter . toString ( ) ; }
Read all data from the given reader into a buffer and return it as a single String.
If an I/O error occurs while reading the reader, it is passed through to the caller.
The reader is closed when before returning.

@param  reader       Open character reader.
@return              All characters read from reader accumulated as a single String.
@throws IOException  If an error occurs reading from the reader.