code: @NullSafe
    public static byte[] toByteArray(InputStream in) throws IOException {
  
      Assert.notNull(in, "The InputStream to read bytes from cannot be null");
  
      ByteArrayOutputStream out = new ByteArrayOutputStream(in.available());
  
      byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
  
      int bytesRead;
  
      while ((bytesRead = in.read(buffer)) != -1) {
        out.write(buffer, 0, bytesRead);
        out.flush();
      }
  
      return out.toByteArray();
    }
docs: Reads the contents of the specified {@link InputStream} into a byte array.
  
  @param in the {@link InputStream} to read content from.
  @return a byte array containing the contents of the given {@link InputStream}.
  @throws IOException if an I/O error occurs while reading the {@link InputStream}.
  @throws NullPointerException if the {@link InputStream} source is null.
  @see java.io.ByteArrayOutputStream
  @see java.io.InputStream