private static long copy(InputStream from, OutputStream to) throws IOException {
    checkNotNull(from, "from");
    checkNotNull(to, "to");
    byte[] buf = new byte[BUF_SIZE];
    long total = 0;
    while (true) {
      int r = from.read(buf);
      if (r == -1) {
        break;
      }
      to.write(buf, 0, r);
      total += r;
    }
    return total;
  }
Adapted from {@code com.google.common.io.ByteStreams.copy()}.
core/src/main/java/feign/Util.java