/** * Reads all data from the given stream as character data in the given character set and closes it on completion * or errors. * * @param in Input stream containing character data. * @param charset Character set of data in stream. * * @return String of all data in stream. * * @throws IOException On IO errors. */ public static String readString(final InputStream in, final Charset charset) throws IOException { final Reader reader = new InputStreamReader(in, charset); final StringBuilder builder = new StringBuilder(); final CharBuffer buffer = CharBuffer.allocate(2048); try { while (reader.read(buffer) > -1) { buffer.flip(); builder.append(buffer); } } finally { closeQuietly(reader); } return builder.toString(); }