Java tutorial
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { /** * Convert input stream to string * * @param input * @return * @throws IOException */ public static byte[] getBytes(InputStream input) throws IOException { byte[] buffer = new byte[8192]; int bytesRead; ByteArrayOutputStream output = new ByteArrayOutputStream(); while ((bytesRead = input.read(buffer)) != -1) { output.write(buffer, 0, bytesRead); } return output.toByteArray(); } }