Here you can find the source of inputStreamToBytes(InputStream in)
public static byte[] inputStreamToBytes(InputStream in)
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { /**/*from w w w . j av a2 s . c o m*/ * Converts an InputStream to a byte[] * */ public static byte[] inputStreamToBytes(InputStream in) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { byte[] buffer = new byte[1024]; int len; while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } } catch (Exception e) { System.out.println("Error converting InputStream to byte[]: " + e.getMessage()); } return out.toByteArray(); } }