mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-15 14:56:05 -04:00
Fix crash
This commit is contained in:
parent
6e79d287f3
commit
61abed04f3
@ -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()))
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user