MCPcopy Create free account
hub / github.com/diffplug/goomph / download

Method download

src/main/java/com/diffplug/gradle/FileMisc.java:57–70  ·  view source on GitHub ↗

Downloads the url to the destination file (with support for redirects).

(String url, File dst)

Source from the content-addressed store, hash-verified

55public class FileMisc {
56 /** Downloads the url to the destination file (with support for redirects). */
57 public static void download(String url, File dst) throws IOException {
58 mkdirs(dst.getParentFile());
59 OkHttpClient client = new OkHttpClient.Builder().build();
60 Request req = new Request.Builder().url(url).build();
61 try (Response response = client.newCall(req).execute();
62 BufferedSink sink = Okio.buffer(Okio.sink(dst))) {
63 try (ResponseBody body = response.body()) {
64 if (body == null) {
65 throw new IllegalArgumentException("Body was expected to be non-null");
66 }
67 sink.writeAll(body.source());
68 }
69 }
70 }
71
72 ///////////////////////////////////////////////////////////////////
73 // Replacements for File.* which check exceptional return values //

Callers 3

installMethod · 0.95
bundleToVersionMethod · 0.95
installMethod · 0.95

Calls 4

mkdirsMethod · 0.95
executeMethod · 0.80
buildMethod · 0.45
sourceMethod · 0.45

Tested by

no test coverage detected