/** * Reads all data from the given reader. * * @param reader Reader over character data. * @param sizeHint Estimate of amount of data to be read in number of characters. * * @return Data read from reader. * * @throws StreamException on stream IO errors. */ public static String readAll(final Reader reader, final int sizeHint) throws StreamException { final CharArrayWriter writer = new CharArrayWriter(sizeHint); final char[] buffer = new char[CHUNK_SIZE]; int len; try { while ((len = reader.read(buffer)) > 0) { writer.write(buffer, 0, len); } } catch (IOException e) { throw new StreamException(e); } finally { closeReader(reader); closeWriter(writer); } return writer.toString(); }