Here you can find the source of inputStreamToReaderToString(InputStream in)
public static String inputStreamToReaderToString(InputStream in) throws Exception
//package com.java2s; //License from project: Apache License import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringWriter; public class Main { public static String inputStreamToReaderToString(InputStream in) throws Exception { char[] buf = new char[4096]; int len;//from ww w . j a va 2 s.c o m InputStreamReader reader = null; StringWriter writer = null; try { reader = new InputStreamReader(in, "UTF-8"); writer = new StringWriter(); while ((len = reader.read(buf)) >= 0) { writer.write(buf, 0, len); } writer.flush(); } finally { if (reader != null) { reader.close(); } if (writer != null) { writer.close(); } } return (writer == null ? null : writer.toString()); } }