aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/config/ConfigIO.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/config/ConfigIO.java')
-rw-r--r--src/main/java/config/ConfigIO.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/main/java/config/ConfigIO.java b/src/main/java/config/ConfigIO.java
new file mode 100644
index 0000000000..4898c9b58d
--- /dev/null
+++ b/src/main/java/config/ConfigIO.java
@@ -0,0 +1,49 @@
+package config;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+public class ConfigIO {
+
+ private static final String CONFIG_PATH = "main/java/config/config.properties";
+ private static final int CONFIG_SIZE = 0;
+
+ private static Properties config;
+
+ private ConfigIO() {
+
+ }
+
+ public static void load() {
+ config = new Properties();
+ try {
+ config.load(new FileInputStream(CONFIG_PATH));
+ } catch (IOException e) {
+ throw new IllegalStateException("Failed to load KekzTech config!");
+ }
+ if(config.size() != CONFIG_SIZE) {
+ throw new IllegalStateException("KekzTech config is not expected size!");
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T get(String key, T valueType) {
+ if(config.size() != CONFIG_SIZE) {
+ throw new IllegalStateException("Tried to access config without loading it first");
+ }
+ return (T) config.get((Object) key);
+ }
+
+ public static void saveConfig() {
+ try {
+ config = (config == null) ? new Properties() : config;
+ config.setProperty("key", "value");
+ config.store(new FileOutputStream(CONFIG_PATH), "Welcome to KekzTech's config file :)");
+ } catch (IOException e) {
+ System.err.println("Failed to save changes to KekzTech config. Settings may be lost.");
+ }
+ }
+
+}