Update FaWe #7

Zusammengeführt
Lixfel hat 467 Commits von update nach main 2024-11-28 22:27:32 +01:00 zusammengeführt
2 geänderte Dateien mit 15 neuen und 11 gelöschten Zeilen
Nur Änderungen aus Commit a0ef151341 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -554,8 +554,15 @@ public class MainUtil {
}
public static BufferedImage readImage(URL url) throws IOException {
try (final InputStream stream = readImageStream(url.toURI())) {
return readImage(stream);
} catch (URISyntaxException e) {
throw new IOException("failed to parse url to uri reference", e);
}
}
public static InputStream readImageStream(final URI uri) throws IOException {
try {
final URI uri = url.toURI();
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(uri).GET();
if (uri.getHost().equalsIgnoreCase("i.imgur.com")) {
@ -566,16 +573,13 @@ public class MainUtil {
requestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream()
);
try (final InputStream body = response.body()) {
if (response.statusCode() > 299) {
throw new IOException("Expected 2xx as response code, but received " + response.statusCode());
}
return readImage(body);
final InputStream body = response.body();
if (response.statusCode() > 299) {
throw new IOException("Expected 2xx as response code, but received " + response.statusCode());
}
return body;
} catch (InterruptedException e) {
throw new IOException("request was interrupted", e);
} catch (URISyntaxException e) {
throw new IOException("failed to parse url to uri reference", e);
}
}

Datei anzeigen

@ -176,8 +176,8 @@ public class ImageUtil {
}
public static BufferedImage load(URI uri) throws InputParseException {
try {
return MainUtil.readImage(getInputStream(uri));
try (final InputStream stream = getInputStream(uri)) {
return MainUtil.readImage(stream);
} catch (IOException e) {
throw new InputParseException(TextComponent.of(e.getMessage()));
}
@ -190,7 +190,7 @@ public class ImageUtil {
File file = new File(uri.getPath());
return new FileInputStream(file);
}
return new URL(uriStr).openStream();
return MainUtil.readImageStream(uri);
} catch (IOException e) {
throw new InputParseException(TextComponent.of(e.getMessage()));
}