aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2021-02-27 16:23:05 +0200
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2021-02-27 16:23:05 +0200
commit61f953a2c88047ccc5fb2de0b91e661503d0f06a (patch)
tree2f5be9d66734f5455cd9970d0ea3d88a066cd164 /src/main/java
parent764a436c529c9d2bb53ded3f8d9917ec18ab669c (diff)
downloadLibGui-61f953a2c88047ccc5fb2de0b91e661503d0f06a.tar.gz
LibGui-61f953a2c88047ccc5fb2de0b91e661503d0f06a.tar.bz2
LibGui-61f953a2c88047ccc5fb2de0b91e661503d0f06a.zip
Move config handling to Path
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java
index d9bc2d5..acd8c5e 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java
@@ -14,9 +14,10 @@ import io.github.cottonmc.jankson.JanksonFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import java.io.File;
-import java.io.FileOutputStream;
+import java.io.InputStream;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
public class LibGuiClient implements ClientModInitializer {
public static final Logger logger = LogManager.getLogger();
@@ -37,11 +38,15 @@ public class LibGuiClient implements ClientModInitializer {
public static LibGuiConfig loadConfig() {
try {
- File file = new File(FabricLoader.getInstance().getConfigDirectory(),"libgui.json5");
+ Path file = FabricLoader.getInstance().getConfigDir().resolve("libgui.json5");
- if (!file.exists()) saveConfig(new LibGuiConfig());
+ if (Files.notExists(file)) saveConfig(new LibGuiConfig());
- JsonObject json = jankson.load(file);
+ JsonObject json;
+ try (InputStream in = Files.newInputStream(file)) {
+ json = jankson.load(in);
+ }
+
config = jankson.fromJson(json, LibGuiConfig.class);
/*
@@ -60,13 +65,11 @@ public class LibGuiClient implements ClientModInitializer {
public static void saveConfig(LibGuiConfig config) {
try {
- File file = new File(FabricLoader.getInstance().getConfigDirectory(),"libgui.json5");
+ Path file = FabricLoader.getInstance().getConfigDir().resolve("libgui.json5");
JsonElement json = jankson.toJson(config);
String result = json.toJson(true, true);
- try (FileOutputStream out = new FileOutputStream(file, false)) {
- out.write(result.getBytes(StandardCharsets.UTF_8));
- }
+ Files.write(file, result.getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
logger.error("[LibGui] Error saving config: {}", e.getMessage());
}