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
This commit is contained in:
parent
9d69098605
commit
514e83e604
@ -106,9 +106,9 @@ public class RepoUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (downloader != null && downloader.getFile() != null) {
|
if (downloader != null && downloader.outputFile != null) {
|
||||||
if (!downloader.getFile().delete()) {
|
if (!downloader.outputFile.delete()) {
|
||||||
Log.w(TAG, "Couldn't delete file: " + downloader.getFile().getAbsolutePath());
|
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
|
// 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:
|
// successful download, then we will have a file ready to use:
|
||||||
cacheTag = downloader.getCacheTag();
|
cacheTag = downloader.getCacheTag();
|
||||||
processDownloadedFile(downloader.getFile());
|
processDownloadedFile(downloader.outputFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ public abstract class Downloader {
|
|||||||
|
|
||||||
private final OutputStream outputStream;
|
private final OutputStream outputStream;
|
||||||
|
|
||||||
private final File outputFile;
|
public final File outputFile;
|
||||||
|
|
||||||
protected final URL sourceUrl;
|
protected final URL sourceUrl;
|
||||||
protected String cacheTag;
|
protected String cacheTag;
|
||||||
@ -78,15 +78,6 @@ public abstract class Downloader {
|
|||||||
return cacheTag != null;
|
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();
|
public abstract boolean hasChanged();
|
||||||
|
|
||||||
protected abstract int totalDownloadSize();
|
protected abstract int totalDownloadSize();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user