stream To Bytes
import java.io.ByteArrayOutputStream; import java.io.InputStream; class Main { public static byte[] streamToBytes(InputStream is) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int i = -1; try { byte[] bytes = new byte[1024]; while ((i = is.read(bytes)) != -1) { baos.write(bytes, 0, i); bytes = new byte[1024]; } return baos.toByteArray(); } catch (Exception e) { } return null; } }