Skip to content

Commit

Permalink
✨ Add missing DataIo overloads for URL
Browse files Browse the repository at this point in the history
  • Loading branch information
XyperCode committed Nov 10, 2023
1 parent 7a57121 commit 94b3bb5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/ultreon/data/DataIo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public static <T extends IType<?>> T read(File file, T... type) throws IOExcepti
}
}

@SafeVarargs
public static <T extends IType<?>> T read(URL url, T... type) throws IOException {
try (InputStream stream = url.openStream()) {
return read(stream, type);
}
}

@SafeVarargs
@SuppressWarnings("unchecked")
public static <T extends IType<?>> T read(InputStream stream, T... type) throws IOException {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 94b3bb5

Please sign in to comment.