Skip to content

Commit

Permalink
fix: correct variable names and add some useful notation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianhua Ran committed Mar 9, 2018
1 parent e45ffa5 commit 503916b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ private void syncCacheToDB(int id) {
FileDownloadLog.d(this, "sync cache to db %d", id);
}

// need to attention that the `sofar` in `FileDownloadModel` database will
// be updated even through this is a multiple connections task. But the
// multi-connections task only concern about the `ConnectionModel` database,
// so it doesn't matter in current.
realDatabase.update(cachedDatabase.find(id));
final List<ConnectionModel> modelList = cachedDatabase.findConnectionModel(id);
realDatabase.removeConnections(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ private ConnectTask(ConnectionProfile profile,
this.profile = profile;
}

void updateConnectionProfile(long haveFinishedOffset) {
if (haveFinishedOffset == profile.currentOffset) {
void updateConnectionProfile(long downloadedOffset) {
if (downloadedOffset == profile.currentOffset) {
if (FileDownloadLog.NEED_LOG) {
FileDownloadLog.w(this, "no data download, no need to update");
}
return;
}
final long newContentLength =
profile.contentLength - (haveFinishedOffset - profile.currentOffset);
profile.contentLength - (downloadedOffset - profile.currentOffset);
profile = ConnectionProfile.ConnectionProfileBuild.buildConnectionProfile(
profile.startOffset,
haveFinishedOffset,
downloadedOffset,
profile.endOffset,
newContentLength);
if (FileDownloadLog.NEED_LOG) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void run() {
//update currentOffset in ConnectionProfile
final long downloadedOffset = getDownloadedOffset();
if (downloadedOffset > 0) {
connectTask.updateConnectionProfile(fetchDataTask.currentOffset);
connectTask.updateConnectionProfile(downloadedOffset);
}
}
callback.onRetry(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void run() throws IOException, IllegalAccessException, IllegalArgumentExc

if (this.contentLength > 0 && contentLength != this.contentLength) {
final String range;
if (endOffset <= 0) {
if (endOffset == ConnectionProfile.RANGE_INFINITE) {
range = FileDownloadUtils.formatString("range[%d-)", currentOffset);
} else {
range = FileDownloadUtils.formatString("range[%d-%d)", currentOffset, endOffset);
Expand Down

0 comments on commit 503916b

Please sign in to comment.