Fix crash

This commit is contained in:
huanghongxun 2019-12-14 12:14:08 +08:00
parent 6e79d287f3
commit 61abed04f3
3 changed files with 18 additions and 22 deletions

View File

@ -237,7 +237,7 @@ public class FileDownloadTask extends Task<Void> {
}
int contentLength = con.getContentLength();
if (contentLength < 1)
if (contentLength < 0)
throw new IOException("The content length is invalid.");
if (!FileUtils.makeDirectory(file.getAbsoluteFile().getParentFile()))

View File

@ -89,7 +89,7 @@ public final class GetTask extends Task<String> {
updateProgress(0);
HttpURLConnection conn = NetworkUtils.createConnection(url);
if (checkETag) repository.injectConnection(conn);
conn.connect();
conn = NetworkUtils.resolveConnection(conn);
if (conn.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
// Handle cache

View File

@ -36,26 +36,22 @@ public final class NetworkUtils {
}
public static String withQuery(String baseUrl, Map<String, String> params) {
try {
StringBuilder sb = new StringBuilder(baseUrl);
boolean first = true;
for (Entry<String, String> param : params.entrySet()) {
if (param.getValue() == null)
continue;
if (first) {
sb.append('?');
first = false;
} else {
sb.append('&');
}
sb.append(URLEncoder.encode(param.getKey(), "UTF-8"));
sb.append('=');
sb.append(URLEncoder.encode(param.getValue(), "UTF-8"));
StringBuilder sb = new StringBuilder(baseUrl);
boolean first = true;
for (Entry<String, String> param : params.entrySet()) {
if (param.getValue() == null)
continue;
if (first) {
sb.append('?');
first = false;
} else {
sb.append('&');
}
return sb.toString();
} catch (IOException e) {
throw new UncheckedIOException(e);
sb.append(encodeURL(param.getKey()));
sb.append('=');
sb.append(encodeURL(param.getValue()));
}
return sb.toString();
}
public static HttpURLConnection createConnection(URL url) throws IOException {
@ -198,8 +194,8 @@ public final class NetworkUtils {
public static URL toURL(String str) {
try {
return new URL(URLEncoder.encode(str, "UTF-8"));
} catch (MalformedURLException | UnsupportedEncodingException e) {
return new URL(str);
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
}