Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static String drain(InputStream inputStream) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int buffer; while ((buffer = inputStream.read()) >= 0) { baos.write(buffer); } return baos.toString(); } }