How to use Apache Commons IOUtils to convert an InputStream to a byte array.
Using Apache Commons IOUtils:
InputStream is = ...; byte[] bytes = IOUtils.toByteArray(is);
Or, using Java 9:
InputStream is = ...; byte[] bytes = is.readAllBytes();