From 94b3bb58bcb677ca4ac9bf5f75d2ee0e9df51c9e Mon Sep 17 00:00:00 2001 From: XyperCode Date: Fri, 10 Nov 2023 19:02:03 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20missing=20DataIo=20overloads?= =?UTF-8?q?=20for=20URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ultreon/data/DataIo.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/com/ultreon/data/DataIo.java b/src/main/java/com/ultreon/data/DataIo.java index 18ddc7e..3612e50 100644 --- a/src/main/java/com/ultreon/data/DataIo.java +++ b/src/main/java/com/ultreon/data/DataIo.java @@ -18,6 +18,13 @@ public static > T read(File file, T... type) throws IOExcepti } } + @SafeVarargs + public static > T read(URL url, T... type) throws IOException { + try (InputStream stream = url.openStream()) { + return read(stream, type); + } + } + @SafeVarargs @SuppressWarnings("unchecked") public static > T read(InputStream stream, T... type) throws IOException { @@ -75,6 +82,12 @@ public static void write(IType type, File file) throws IOException { } } + public static void write(IType type, URL file) throws IOException { + try (OutputStream stream = file.openConnection().getOutputStream()) { + write(type, stream); + } + } + public static void write(IType type, OutputStream stream) throws IOException { DataOutputStream outputStream; if (stream instanceof DataOutputStream) {