From 514e83e60448cf68747a14fa1ef2b6f4708f48fe Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 2 Apr 2016 23:38:52 +0200 Subject: [PATCH] convert Downloader's outputFile to a read-only property Since Downloader's outputFile variable is final, it can safely be used as a public property variable. This makes it simple to use in subclasses. Making it a public final variable rather than a getter also communicates that the value does not change since there is no getter method that could potentially change it. http://binkley.blogspot.com/2005/01/read-only-properties-in-java.html --- app/src/main/java/org/fdroid/fdroid/RepoUpdater.java | 8 ++++---- .../main/java/org/fdroid/fdroid/net/Downloader.java | 11 +---------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java b/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java index 2c75c06bd..653e975b2 100644 --- a/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java +++ b/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java @@ -106,9 +106,9 @@ public class RepoUpdater { } } catch (IOException e) { - if (downloader != null && downloader.getFile() != null) { - if (!downloader.getFile().delete()) { - Log.w(TAG, "Couldn't delete file: " + downloader.getFile().getAbsolutePath()); + if (downloader != null && downloader.outputFile != null) { + if (!downloader.outputFile.delete()) { + Log.w(TAG, "Couldn't delete file: " + downloader.outputFile.getAbsolutePath()); } } @@ -136,7 +136,7 @@ public class RepoUpdater { // Don't worry about checking the status code for 200. If it was a // successful download, then we will have a file ready to use: cacheTag = downloader.getCacheTag(); - processDownloadedFile(downloader.getFile()); + processDownloadedFile(downloader.outputFile); } } diff --git a/app/src/main/java/org/fdroid/fdroid/net/Downloader.java b/app/src/main/java/org/fdroid/fdroid/net/Downloader.java index 61b6af116..45ba5b884 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/Downloader.java +++ b/app/src/main/java/org/fdroid/fdroid/net/Downloader.java @@ -27,7 +27,7 @@ public abstract class Downloader { private final OutputStream outputStream; - private final File outputFile; + public final File outputFile; protected final URL sourceUrl; protected String cacheTag; @@ -78,15 +78,6 @@ public abstract class Downloader { return cacheTag != null; } - /** - * Only available if you passed a context object into the constructor - * (rather than an outputStream, which may or may not be associated with - * a file). - */ - public File getFile() { - return outputFile; - } - public abstract boolean hasChanged(); protected abstract int totalDownloadSize();