/** * Download a file. * * @param uri URI * @param dest File destination * @return Response status code * @throws IOException * @throws HttpErrorStatusException */ public int downloadFile(URI uri, File dest) throws IOException, HttpErrorStatusException { return downloadFile(uri, DEFAULT_SOCKET_TIMEOUT_MS, dest); }
@Override public void fetchSegmentToLocal(final String uri, final File tempFile) throws Exception { RetryPolicies.exponentialBackoffRetryPolicy(_retryCount, _retryWaitMs, 5).attempt(() -> { try { int statusCode = _httpClient.downloadFile(new URI(uri), tempFile); _logger.info("Downloaded file from: {} to: {}; Length of downloaded file: {}; Response status code: {}", uri, tempFile, tempFile.length(), statusCode); return true; } catch (HttpErrorStatusException e) { int statusCode = e.getStatusCode(); if (statusCode >= 500) { // Temporary exception _logger.warn("Caught temporary exception while downloading file from: {}, will retry", uri, e); return false; } else { // Permanent exception _logger.error("Caught permanent exception while downloading file from: {}, won't retry", uri, e); throw e; } } catch (Exception e) { _logger.warn("Caught temporary exception while downloading file from: {}, will retry", uri, e); return false; } }); }