Here you can find the source of inputStreamToString(InputStream is)
public static String inputStreamToString(InputStream is) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; public class Main { public static String inputStreamToString(InputStream is) throws IOException { if (is == null) { throw new IllegalArgumentException("InputStream was null!"); }//from ww w .j av a 2 s .co m final int bufferSize = 1024; final char[] buffer = new char[bufferSize]; final StringBuilder out = new StringBuilder(); Reader in = new InputStreamReader(is, "UTF-8"); for (;;) { int rsz = in.read(buffer, 0, buffer.length); if (rsz < 0) { break; } out.append(buffer, 0, rsz); } return out.toString(); } }