Here you can find the source of loadAsText(InputStream in, String encoding, int bufferSize)
public static String loadAsText(InputStream in, String encoding, int bufferSize) throws IOException
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { public static String loadAsText(InputStream in, String encoding) throws IOException { return loadAsText(in, encoding, 4096); }/*from www.j a v a2 s . c om*/ public static String loadAsText(InputStream in, String encoding, int bufferSize) throws IOException { InputStreamReader reader = new InputStreamReader(in, encoding); char[] buffer = new char[bufferSize]; int offset = 0; for (;;) { int remain = buffer.length - offset; if (remain <= 0) { char[] newBuffer = new char[buffer.length * 2]; System.arraycopy(buffer, 0, newBuffer, 0, offset); buffer = newBuffer; remain = buffer.length - offset; } int numRead = reader.read(buffer, offset, remain); if (numRead == -1) { break; } offset += numRead; } return new String(buffer, 0, offset); } }