Here you can find the source of inputStreamToString(InputStream is)
public static String inputStreamToString(InputStream is)
//package com.java2s; //License from project: Apache License import java.io.InputStream; import java.io.IOException; import java.io.ByteArrayOutputStream; import java.io.InputStreamReader; import java.io.CharArrayWriter; public class Main { private static final int BUFFERSIZE = 8192; public static String inputStreamToString(InputStream is) { return new String(exhaustInputStreamUnchecked(is)); }//from ww w . ja v a2s .co m public static byte[] exhaustInputStreamUnchecked(InputStream in) { try { return exhaustInputStream(in); } catch (IOException e) { throw new RuntimeException(e); } } public static char[] exhaustInputStreamUnchecked(InputStream in, String encoding) { try { return exhaustInputStream(in, encoding); } catch (IOException e) { throw new RuntimeException(e); } } public static byte[] exhaustInputStream(InputStream in) throws IOException { assert in != null; ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[16384]; int c; while ((c = in.read(buffer)) >= 0) { out.write(buffer, 0, c); } return out.toByteArray(); } public static char[] exhaustInputStream(InputStream in, String encoding) throws IOException { assert in != null; assert encoding != null; InputStreamReader charin = new InputStreamReader(in, encoding); CharArrayWriter out = new CharArrayWriter(); char[] buffer = new char[BUFFERSIZE]; int c; while ((c = charin.read(buffer)) >= 0) { out.write(buffer, 0, c); } return out.toCharArray(); } }