Here you can find the source of readStreamToString(InputStream stream, Charset encoding)
public static String readStreamToString(InputStream stream, Charset encoding) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; public class Main { private static final int BUFFER_SIZE = 4 * 1024; public static String readStreamToString(InputStream stream, Charset encoding) throws IOException { StringBuilder builder = new StringBuilder(); InputStreamReader reader = new InputStreamReader(stream, encoding); char[] buffer = new char[BUFFER_SIZE]; int length; while ((length = reader.read(buffer)) != -1) { builder.append(buffer, 0, length); }//from w ww . j a v a2 s .com reader.close(); return builder.toString(); } }