private static byte[] streamToBytes(InputStream is){ ByteArrayOutputStream os = new ByteArrayOutputStream(1024); byte[] buffer = new byte[1024]; int len; try { while((len = is.read(buffer)) >=0){ os.write(buffer,0,len); } } catch (IOException e) { e.printStackTrace(); } return os.toByteArray(); }