Here you can find the source of inputStreamToString(final InputStream is, final int bufferSize)
public static String inputStreamToString(final InputStream is, final int bufferSize)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.UnsupportedEncodingException; public class Main { public static String inputStreamToString(final InputStream is, final int bufferSize) { final char[] buffer = new char[bufferSize]; final StringBuilder out = new StringBuilder(); try (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); }/*from w w w . ja v a2 s . c om*/ } catch (UnsupportedEncodingException ex) { return ""; /* ... */ } catch (IOException ex) { return ""; /* ... */ } return out.toString(); } }