Skip to content

Commit 4fc4590

Browse files
committed
Attempt to fix unknown host exceptions in update checkers
Signed-off-by: KiriCattus <19393068+KiriCattus@users.noreply.github.com>
1 parent 6dd7d31 commit 4fc4590

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/commander/java/com/mcmoddev/mmdbot/commander/updatenotifiers/SharedVersionHelpers.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
import java.io.IOException;
3333
import java.io.InputStream;
3434
import java.io.InputStreamReader;
35-
import java.net.URL;
35+
import java.net.URI;
36+
import java.net.http.HttpClient;
37+
import java.net.http.HttpRequest;
38+
import java.net.http.HttpResponse;
3639
import java.nio.charset.StandardCharsets;
37-
import java.util.regex.Pattern;
3840

3941
/**
4042
* Helper methods for the Fabric and Quilt mod loader.
@@ -56,9 +58,14 @@ public static InputStreamReader getReader(final String urlString) {
5658
@Nullable
5759
public static InputStream getStream(final String urlString) {
5860
try {
59-
final var url = new URL(urlString);
60-
return url.openStream();
61-
} catch (IOException ex) {
61+
HttpClient client = HttpClient.newHttpClient();
62+
HttpRequest request = HttpRequest.newBuilder()
63+
.uri(URI.create(urlString))
64+
.build();
65+
66+
HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
67+
return response.body();
68+
} catch (IOException | InterruptedException ex) {
6269
TheCommander.LOGGER.error("Failed to open input stream", ex);
6370
return null;
6471
}

0 commit comments

Comments
 (0)