From cb34b448de59c0ce8e435861a3a548a723cfdbdc Mon Sep 17 00:00:00 2001 From: aro Date: Sat, 31 Dec 2022 10:48:43 +0100 Subject: [PATCH] feat: copy using util class --- .../artelnatif/nicko/i18n/LocaleManager.java | 22 ++++++++++--------- .../net/artelnatif/nicko/utils/FileUtils.java | 13 ----------- 2 files changed, 12 insertions(+), 23 deletions(-) delete mode 100644 nicko-core/src/main/java/net/artelnatif/nicko/utils/FileUtils.java diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/i18n/LocaleManager.java b/nicko-core/src/main/java/net/artelnatif/nicko/i18n/LocaleManager.java index 6fcf13b..bc70028 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/i18n/LocaleManager.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/i18n/LocaleManager.java @@ -1,11 +1,9 @@ package net.artelnatif.nicko.i18n; +import de.studiocode.invui.util.IOUtils; import net.artelnatif.nicko.NickoBukkit; import java.io.*; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; import java.util.Arrays; import java.util.Properties; @@ -32,14 +30,18 @@ public class LocaleManager { } public void installCustomLanguageFile() { - final InputStream resource = instance.getResource("locale_en.properties"); - - try { - instance.getLogger().info("Installing custom language file as \"custom.properties\""); - // TODO: 12/26/22 This throws an error! - Files.copy(resource, Paths.get(file.toURI()), StandardCopyOption.REPLACE_EXISTING); + try (InputStream stream = this.getClass().getResourceAsStream("locale_en.properties")) { + try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file))) { + if (stream != null) { + IOUtils.copy(stream, outputStream, 8 * 1024); + instance.getLogger().info("Installing custom language file as \"custom.properties\""); + } + } } catch (IOException e) { - // TODO: 12/19/22 Handle error + instance.getLogger().warning("Couldn't get English resource file! Skipping."); + if (LocaleManager.getFallback() != Locale.ENGLISH) { + LocaleManager.setFallback(Locale.ENGLISH); + } throw new RuntimeException(e); } } diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/utils/FileUtils.java b/nicko-core/src/main/java/net/artelnatif/nicko/utils/FileUtils.java deleted file mode 100644 index de8b2de..0000000 --- a/nicko-core/src/main/java/net/artelnatif/nicko/utils/FileUtils.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.artelnatif.nicko.utils; - -import java.io.File; -import java.io.IOException; - -public class FileUtils { - public static boolean isPresentOrCreate(File file) throws IOException { - if (!file.exists()) { - return file.createNewFile(); - } - return true; - } -}