code: public static byte[] bytes(InputStream in) throws IOException {
          if(in == null)
              throw new IllegalArgumentException("input stream cannot be null");
  
          ByteArrayOutputStream bout = new ByteArrayOutputStream(1024);
          byte[] bytes = new byte[1024];
  
          for (int x = in.read(bytes); x != -1; x = in.read(bytes))
              bout.write(bytes, 0, x);
  
          return bout.toByteArray();
      }
docs: Reads contents of the input stream fully and returns it as byte array.
  
  @param in InputStream to read from.
  @return contents of the input stream fully as byte array
  @throws IOException in case of IO error
  @throws IllegalArgumentException if stream is null