public static byte[] toByteArray(InputStream in) throws IOException {
    checkNotNull(in, "in");
    try {
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      copy(in, out);
      return out.toByteArray();
    } finally {
      ensureClosed(in);
    }
  }
Adapted from {@code com.google.common.io.ByteStreams.toByteArray()}.
core/src/main/java/feign/Util.java