Here you can find the source of readInputStreamToString(InputStream inputStream)
public static String readInputStreamToString(InputStream inputStream)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; public class Main { public static String readInputStreamToString(InputStream inputStream) { return readInputStreamToString(inputStream, "UTF-8"); }/* w ww. j a v a2s. co m*/ public static String readInputStreamToString(InputStream inputStream, String encoding) { String rs = null; try { ByteBuffer byteBuffer = ByteBuffer.allocate(1024 * 1024 * 1024); int length = -1; int bufferSize = 128; byte[] buffer = new byte[bufferSize]; while ((length = inputStream.read(buffer)) != -1) { if (length != bufferSize) { System.arraycopy(buffer, 0, buffer, 0, length); } byteBuffer.put(buffer); } rs = new String(byteBuffer.array(), encoding); } catch (IOException e) { } finally { // try { // inputStream.close(); // } catch (IOException e1) { // e1.printStackTrace(); // } try { inputStream.close(); } catch (IOException e1) { e1.printStackTrace(); } } return rs; } }