From 21abce0139bc8a8abba2fde04390259e03e53cde Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Sat, 2 Apr 2022 16:19:47 +0200 Subject: [PATCH] Hacky way to disable reporting for small files --- .../main/java/btools/routingapp/DownloadService.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/brouter-routing-app/src/main/java/btools/routingapp/DownloadService.java b/brouter-routing-app/src/main/java/btools/routingapp/DownloadService.java index 7e608fc..f1ec4bf 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/DownloadService.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/DownloadService.java @@ -203,18 +203,21 @@ public class DownloadService extends Service implements ProgressListener { return connection.getResponseCode() == HttpURLConnection.HTTP_OK; } + private void downloadFile(URL downloadUrl, File outputFile, boolean limitDownloadSpeed) throws IOException, InterruptedException { + // For all those small files the progress reporting is really noisy + boolean reportDownloadProgress = limitDownloadSpeed; HttpURLConnection connection = (HttpURLConnection) downloadUrl.openConnection(); connection.setConnectTimeout(5000); connection.connect(); - updateProgress("Connecting..."); + if (reportDownloadProgress) updateProgress("Connecting..."); if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new IOException("HTTP Request failed"); } int fileLength = connection.getContentLength(); - updateProgress("Loading"); + if (reportDownloadProgress) updateProgress("Loading"); try ( InputStream input = connection.getInputStream(); @@ -233,9 +236,9 @@ public class DownloadService extends Service implements ProgressListener { if (fileLength > 0) // only if total length is known { int pct = (int) (total * 100 / fileLength); - updateProgress("Progress " + pct + "%"); + if (reportDownloadProgress) updateProgress("Progress " + pct + "%"); } else { - updateProgress("Progress (unknown size)"); + if (reportDownloadProgress) updateProgress("Progress (unknown size)"); } output.write(buffer, 0, count);