From 494b3227b6bebc2509eeae9927a437709a6d1180 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 8 Mar 2024 14:46:43 +0700 Subject: [PATCH] [FIX] Remove deprecated 'new URL' --- .../java/pro/gravit/launcher/base/profiles/Texture.java | 6 +++++- .../src/main/java/pro/gravit/utils/helper/IOHelper.java | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/Texture.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/Texture.java index 7f917e85..d77fb3b7 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/Texture.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/Texture.java @@ -8,6 +8,8 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Path; import java.util.Arrays; @@ -29,8 +31,10 @@ public Texture(String url, boolean cloak, Map metadata) throws I // Fetch texture byte[] texture; - try (InputStream input = IOHelper.newInput(new URL(url))) { + try (InputStream input = IOHelper.newInput(new URI(url).toURL())) { texture = IOHelper.read(input); + } catch (URISyntaxException e) { + throw new IOException(e); } try (ByteArrayInputStream input = new ByteArrayInputStream(texture)) { IOHelper.readTexture(input, cloak); // Verify texture diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java index 0f008c38..b1a4686f 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java @@ -95,8 +95,8 @@ public static Manifest getManifest(Class clazz) { public static URL convertToURL(String url) { try { - return new URL(url); - } catch (MalformedURLException e) { + return new URI(url).toURL(); + } catch (MalformedURLException | URISyntaxException e) { throw new IllegalArgumentException("Invalid URL", e); } } @@ -576,9 +576,9 @@ public static BufferedImage verifyTexture(BufferedImage skin, boolean cloak) { public static String verifyURL(String url) { try { - new URL(url).toURI(); + new URI(url); return url; - } catch (MalformedURLException | URISyntaxException e) { + } catch (URISyntaxException e) { throw new IllegalArgumentException("Invalid URL", e); } }