Skip to content

Commit

Permalink
fix: fix unexpected content-length raise NumberFormatException
Browse files Browse the repository at this point in the history
closes #107
  • Loading branch information
Jacksgong committed Jul 4, 2018
1 parent 788320c commit 24fac8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,13 @@ public static void assembleBlock(@NonNull DownloadTask task, @NonNull Breakpoint
public static long parseContentLength(@Nullable String contentLength) {
if (contentLength == null) return CHUNKED_CONTENT_LENGTH;

return Long.parseLong(contentLength);
try {
return Long.parseLong(contentLength);
} catch (NumberFormatException ignored) {
Util.d("Util", "parseContentLength failed parse for '" + contentLength + "'");
}

return CHUNKED_CONTENT_LENGTH;
}

public static boolean isNetworkNotOnWifiType(ConnectivityManager manager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ public void assembleBlock_multiBlock() throws Exception {
public void parseContentLength() {
assertThat(Util.parseContentLength(null)).isEqualTo(CHUNKED_CONTENT_LENGTH);
assertThat(Util.parseContentLength("123")).isEqualTo(123L);

assertThat(Util.parseContentLength("-")).isEqualTo(CHUNKED_CONTENT_LENGTH);
}

@Test
Expand Down

0 comments on commit 24fac8e

Please sign in to comment.