Here you can find the source of streamToString(InputStream inputStream, Charset encoding)
public static String streamToString(InputStream inputStream, Charset encoding) throws IOException
//package com.java2s; //License from project: LGPL import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.Charset; public class Main { public static String streamToString(InputStream inputStream, Charset encoding) throws IOException { final int bufferSize = 1024; final char[] buffer = new char[bufferSize]; final StringBuilder out = new StringBuilder(); Reader in = new InputStreamReader(inputStream, encoding); for (;;) { int rsz = in.read(buffer, 0, buffer.length); if (rsz < 0) break; out.append(buffer, 0, rsz);/*from w w w. jav a 2 s . c o m*/ } return out.toString(); } }