Here you can find the source of toString(final InputStream input, final Charset encoding)
public static String toString(final InputStream input, final Charset encoding) throws IOException
//package com.java2s; 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 toString(final InputStream input) throws IOException { return toString(input, Charset.defaultCharset()); }//from w w w . jav a2s .c o m public static String toString(final InputStream input, final Charset encoding) throws IOException { return toString(new InputStreamReader(input, encoding)); } public static String toString(final Reader input) throws IOException { final StringBuilder sb = new StringBuilder(); final char[] buffer = new char[4096]; for (int charsRead; -1 != (charsRead = input.read(buffer));) { sb.append(buffer, 0, charsRead); } return sb.toString(); } }