Hello @kartik,
You need to read each byte from your InputStream and write it to a ByteArrayOutputStream. 
You can then retrieve the underlying byte array by calling toByteArray(); e.g.  
InputStream is = ...
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = is.read(data, 0, data.length)) != -1) {
  buffer.write(data, 0, nRead);
}
return buffer.toByteArray();
Hope this helps!!
If you need to know more about Java, join our Java online course today.
Thank you!!