@Test public void downloadToFile_creates_the_file_if_it_does_not_exist() throws Exception { server.enqueue(new MockResponse().setBody(PONG)); File dir = temp.newFolder(); File file = new File(dir, "ping.txt"); assertThat(file).doesNotExist(); newCall("api/system/ping").downloadToFile(file); assertThat(file).exists().isFile().hasContent(PONG); }
public void downloadToFile(File file) { Request okRequest = buildOkHttpRequest(); try { doDownloadToFile(okRequest, file); } catch (ProtocolException|SocketException|SocketTimeoutException se) { try { doDownloadToFile(okRequest, file); } catch (IOException e2) { throw new IllegalStateException(format("Can not call %s", okRequest.url()), e2); } } catch (IOException e) { throw new IllegalStateException(format("Can not call %s", okRequest.url()), e); } }
HttpCall { public void downloadToFile(File file) { Request okRequest = buildOkHttpRequest(); try { doDownloadToFile(okRequest, file); } catch (ProtocolException|SocketException|SocketTimeoutException se) { try { doDownloadToFile(okRequest, file); } catch (IOException e2) { throw new IllegalStateException(format("Can not call %s", okRequest.url()), e2); } } catch (IOException e) { throw new IllegalStateException(format("Can not call %s", okRequest.url()), e); } } }
HttpCall { public void downloadToFile(File file) { Request okRequest = buildOkHttpRequest(); try { doDownloadToFile(okRequest, file); } catch (ProtocolException|SocketException|SocketTimeoutException se) { try { doDownloadToFile(okRequest, file); } catch (IOException e2) { throw new IllegalStateException(format("Can not call %s", okRequest.url()), e2); } } catch (IOException e) { throw new IllegalStateException(format("Can not call %s", okRequest.url()), e); } } HttpCall(OkHttpClient okClient, HttpUrl baseUrl); }
HttpCall { public void downloadToFile(File file) { Request okRequest = buildOkHttpRequest(); try { doDownloadToFile(okRequest, file); } catch (ProtocolException|SocketException|SocketTimeoutException se) { try { doDownloadToFile(okRequest, file); } catch (IOException e2) { throw new IllegalStateException(format("Can not call %s", okRequest.url()), e2); } } catch (IOException e) { throw new IllegalStateException(format("Can not call %s", okRequest.url()), e); } } HttpCall(OkHttpClient okClient, HttpUrl baseUrl); HttpUrl getBaseUrl(); HttpCall setMethod(HttpMethod m); HttpCall setCredentials(String login, @Nullable String password); HttpCall setAdminCredentials(); HttpCall setAuthenticationToken(String token); HttpCall setParam(String key, @Nullable String value); HttpCall setParams(String key1, @Nullable String value1, String... otherKeysAndNames); HttpCall setHeader(String key, String value); HttpCall setTimeoutMs(long timeoutMs); HttpResponse execute(); HttpResponse executeUnsafely(); void downloadToFile(File file); File downloadToDirectory(File dir); }
HttpCall { public void downloadToFile(File file) { Request okRequest = buildOkHttpRequest(); try { doDownloadToFile(okRequest, file); } catch (ProtocolException|SocketException|SocketTimeoutException se) { try { doDownloadToFile(okRequest, file); } catch (IOException e2) { throw new IllegalStateException(format("Can not call %s", okRequest.url()), e2); } } catch (IOException e) { throw new IllegalStateException(format("Can not call %s", okRequest.url()), e); } } HttpCall(OkHttpClient okClient, HttpUrl baseUrl); HttpUrl getBaseUrl(); HttpCall setMethod(HttpMethod m); HttpCall setCredentials(String login, @Nullable String password); HttpCall setAdminCredentials(); HttpCall setAuthenticationToken(String token); HttpCall setParam(String key, @Nullable String value); HttpCall setParams(String key1, @Nullable String value1, String... otherKeysAndNames); HttpCall setHeader(String key, String value); HttpCall setTimeoutMs(long timeoutMs); HttpResponse execute(); HttpResponse executeUnsafely(); void downloadToFile(File file); File downloadToDirectory(File dir);  }