Hacky way to disable reporting for small files
This commit is contained in:
parent
d74d0af687
commit
21abce0139
1 changed files with 7 additions and 4 deletions
|
@ -203,18 +203,21 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
|
return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void downloadFile(URL downloadUrl, File outputFile, boolean limitDownloadSpeed) throws IOException, InterruptedException {
|
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();
|
HttpURLConnection connection = (HttpURLConnection) downloadUrl.openConnection();
|
||||||
connection.setConnectTimeout(5000);
|
connection.setConnectTimeout(5000);
|
||||||
connection.connect();
|
connection.connect();
|
||||||
|
|
||||||
updateProgress("Connecting...");
|
if (reportDownloadProgress) updateProgress("Connecting...");
|
||||||
|
|
||||||
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
||||||
throw new IOException("HTTP Request failed");
|
throw new IOException("HTTP Request failed");
|
||||||
}
|
}
|
||||||
int fileLength = connection.getContentLength();
|
int fileLength = connection.getContentLength();
|
||||||
updateProgress("Loading");
|
if (reportDownloadProgress) updateProgress("Loading");
|
||||||
|
|
||||||
try (
|
try (
|
||||||
InputStream input = connection.getInputStream();
|
InputStream input = connection.getInputStream();
|
||||||
|
@ -233,9 +236,9 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
if (fileLength > 0) // only if total length is known
|
if (fileLength > 0) // only if total length is known
|
||||||
{
|
{
|
||||||
int pct = (int) (total * 100 / fileLength);
|
int pct = (int) (total * 100 / fileLength);
|
||||||
updateProgress("Progress " + pct + "%");
|
if (reportDownloadProgress) updateProgress("Progress " + pct + "%");
|
||||||
} else {
|
} else {
|
||||||
updateProgress("Progress (unknown size)");
|
if (reportDownloadProgress) updateProgress("Progress (unknown size)");
|
||||||
}
|
}
|
||||||
output.write(buffer, 0, count);
|
output.write(buffer, 0, count);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue