Here you can find the source of readString(final InputStream input, final Charset charset)
public static String readString(final InputStream input, final Charset charset) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; public class Main { public static String readString(final InputStream input, final Charset charset) throws IOException { final byte[] bytes = readBytes(input, 4096); return new String(bytes, charset); }/*from w ww.jav a 2 s . co m*/ public static byte[] readBytes(final InputStream input, final int bufferSize) throws IOException { final ByteArrayOutputStream output = new ByteArrayOutputStream(bufferSize); bufferCopy(input, output, bufferSize); return output.toByteArray(); } public static void bufferCopy(final InputStream input, final OutputStream output, final int bufferSize) throws IOException { final byte[] buffer = new byte[bufferSize]; int count; while ((count = input.read(buffer)) != -1) { output.write(buffer, 0, count); } } }