Skip to content

Commit

Permalink
Fixed download from URL.
Browse files Browse the repository at this point in the history
Generate download temp file name without invalid file name characters.
  • Loading branch information
yukuku committed Sep 26, 2018
1 parent 8ddd90b commit ac32350
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
9 changes: 0 additions & 9 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion Alkitab/src/main/java/yuku/alkitab/base/util/DownloadMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,16 @@ static String downloadTempDirPath() {

@NonNull
static String downloadTempBasename(final String downloadKey) {
return "DownloadMapper-" + downloadKey + ".tmp";
// Return value must be filename-safe.
// So I will remove all non-safe characters and append the hashcode of the downloadKey.
final StringBuilder safe = new StringBuilder(downloadKey.length() + 40);
for (char c : downloadKey.toCharArray()) {
if ('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || '0' <= c && c <= '9') {
safe.append(c);
}
}

return "DownloadMapper-" + safe + downloadKey.hashCode() + ".tmp";
}

public void enqueue(final String downloadKey, final String url, final String title, final Map<String, String> attrs) {
Expand Down Expand Up @@ -155,6 +164,9 @@ public void onError(final Error error) {
final int id = p_id[0];

final CharSequence msg;

AppLog.e(TAG, "@@onError", error.getException());

if (error.isConnectionError()) {
msg = TextUtils.expandTemplate(App.context.getString(R.string.version_download_network_error), title);
} else {
Expand Down

0 comments on commit ac32350

Please sign in to comment.