From ba73203a4276b661d99a5573ad75852802ebfe0e Mon Sep 17 00:00:00 2001 From: JernejTDO Date: Sun, 8 Jun 2025 10:44:03 +0200 Subject: [PATCH] UTD --- .classpath | 40 +++++++ .project | 23 ++++ .settings/org.eclipse.core.resources.prefs | 6 ++ .settings/org.eclipse.jdt.core.prefs | 8 ++ .settings/org.eclipse.m2e.core.prefs | 4 + pom.xml | 65 ++++++++++++ .../triler/code/JsonManager/JsonManager.java | 99 ++++++++++++++++++ target/classes/META-INF/MANIFEST.MF | 4 + .../eu.triler.code/JsonManager/pom.properties | 7 ++ .../maven/eu.triler.code/JsonManager/pom.xml | 65 ++++++++++++ .../triler/code/JsonManager/JsonManager.class | Bin 0 -> 5740 bytes 11 files changed, 321 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 pom.xml create mode 100644 src/main/java/eu/triler/code/JsonManager/JsonManager.java create mode 100644 target/classes/META-INF/MANIFEST.MF create mode 100644 target/classes/META-INF/maven/eu.triler.code/JsonManager/pom.properties create mode 100644 target/classes/META-INF/maven/eu.triler.code/JsonManager/pom.xml create mode 100644 target/classes/eu/triler/code/JsonManager/JsonManager.class diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..f0e9804 --- /dev/null +++ b/.classpath @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..7df6f9d --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + JsonManager + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..29abf99 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..2af1e7b --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=11 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b13bea8 --- /dev/null +++ b/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + eu.triler.code + JsonManager + 1.0 + JsonManager + + 11 + UTF-8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + false + + + + + + + + src/main/resources + true + + + + + + TrilerGit + https://git.triler.eu/api/packages/TrilerCode/maven + + + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + com.google.code.gson + gson + 2.9.1 + + + \ No newline at end of file diff --git a/src/main/java/eu/triler/code/JsonManager/JsonManager.java b/src/main/java/eu/triler/code/JsonManager/JsonManager.java new file mode 100644 index 0000000..62d7cf0 --- /dev/null +++ b/src/main/java/eu/triler/code/JsonManager/JsonManager.java @@ -0,0 +1,99 @@ +package eu.triler.code.JsonManager; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Reader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class JsonManager { + + private static final String LOG_PREFIX = "[NetworkManager] "; + private static final String FOLDER_PREFIX = "[FOLDER MANAGER] "; + private static final String JSON_PREFIX = "[JSON FILE MANAGER] "; + + private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + private static void consoleLog(String message) { + String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")); + System.out.println(timestamp + " " + LOG_PREFIX + message); + } + + public static void createFolder(String basePath, String folderName) { + Path folderPath = Paths.get(basePath, folderName); + if (Files.notExists(folderPath)) { + try { + Files.createDirectories(folderPath); + consoleLog(FOLDER_PREFIX + folderName + " was created in [" + basePath + "]."); + } catch (IOException e) { + consoleLog(FOLDER_PREFIX + "Failed to create folder: " + e.getMessage()); + } + } + } + + public static void createJsonFile(String fileName, JSONObject jsonObject, String path) { + if (path == null || fileName == null || jsonObject == null) { + consoleLog(JSON_PREFIX + "Invalid input to createJsonFile."); + return; + } + + Path filePath = Paths.get(path, fileName + ".json"); + if (Files.notExists(filePath)) { + try (FileWriter writer = new FileWriter(filePath.toFile())) { + writer.write(gson.toJson(jsonObject)); + consoleLog(JSON_PREFIX + fileName + ".json was created."); + } catch (IOException e) { + consoleLog(JSON_PREFIX + "Error creating JSON file: " + e.getMessage()); + } + } + } + + public static JSONObject getJsonBody(String fileName, String path) { + if (path == null || fileName == null) { + consoleLog(JSON_PREFIX + "Invalid input to getJsonBody."); + return null; + } + + Path filePath = Paths.get(path, fileName + ".json"); + if (Files.exists(filePath)) { + try (Reader reader = new FileReader(filePath.toFile())) { + JSONObject jsonObject = (JSONObject) new JSONParser().parse(reader); + consoleLog(JSON_PREFIX + fileName + ".json body was loaded."); + return jsonObject; + } catch (IOException | ParseException e) { + consoleLog(JSON_PREFIX + "Error reading JSON file: " + e.getMessage()); + } + } + return null; + } + + public static void updateJsonBody(String fileName, JSONObject jsonObject, String path) { + if (path == null || fileName == null || jsonObject == null) { + consoleLog(JSON_PREFIX + "Invalid input to updateJsonBody."); + return; + } + + Path filePath = Paths.get(path, fileName + ".json"); + if (Files.exists(filePath)) { + try (FileWriter writer = new FileWriter(filePath.toFile())) { + writer.write(gson.toJson(jsonObject)); + consoleLog(JSON_PREFIX + fileName + ".json body was updated."); + } catch (IOException e) { + consoleLog(JSON_PREFIX + "Error updating JSON file: " + e.getMessage()); + } + } else { + consoleLog(JSON_PREFIX + fileName + ".json does not exist to update."); + } + } +} diff --git a/target/classes/META-INF/MANIFEST.MF b/target/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0e15486 --- /dev/null +++ b/target/classes/META-INF/MANIFEST.MF @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Build-Jdk-Spec: 23 +Created-By: Maven Integration for Eclipse + diff --git a/target/classes/META-INF/maven/eu.triler.code/JsonManager/pom.properties b/target/classes/META-INF/maven/eu.triler.code/JsonManager/pom.properties new file mode 100644 index 0000000..6996ae5 --- /dev/null +++ b/target/classes/META-INF/maven/eu.triler.code/JsonManager/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Sun Jun 08 10:43:04 CEST 2025 +artifactId=JsonManager +groupId=eu.triler.code +m2e.projectLocation=D\:\\Codespace\\JernejTDO\\JsonManager +m2e.projectName=JsonManager +version=1.0 diff --git a/target/classes/META-INF/maven/eu.triler.code/JsonManager/pom.xml b/target/classes/META-INF/maven/eu.triler.code/JsonManager/pom.xml new file mode 100644 index 0000000..b13bea8 --- /dev/null +++ b/target/classes/META-INF/maven/eu.triler.code/JsonManager/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + eu.triler.code + JsonManager + 1.0 + JsonManager + + 11 + UTF-8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + false + + + + + + + + src/main/resources + true + + + + + + TrilerGit + https://git.triler.eu/api/packages/TrilerCode/maven + + + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + com.google.code.gson + gson + 2.9.1 + + + \ No newline at end of file diff --git a/target/classes/eu/triler/code/JsonManager/JsonManager.class b/target/classes/eu/triler/code/JsonManager/JsonManager.class new file mode 100644 index 0000000000000000000000000000000000000000..4908817ebd5d92954125da4e6055840baf46e135 GIT binary patch literal 5740 zcmbtYX?PRI8GZ-LT3KEURvt#F(k zp=X*lO?sp`nv!0m^h`|B8V5>3FKE;IzVG{P|Mo}eJF_cU!ZPJ)Z9lU+voqiEzTfxF zj9>WovF8B12>;ZuNMNm*k2-cTW!lj(D`7^r<*dwhBV&wnpyXYHPhja@W4{qi8JY2D z@9180%n=C2d$-))*WcOIeVafiJ~v^2LNntrfyM1sCg&I#XUIt9%>Zfy>PLD^XVS9w zd5U&NIIXKU-qG3b$qGQ1)7-Jh_DwyTwsiK(X|>x1dV7kKmIy2xkt30=?s#YEJl{C| z5V$ZtW~HO!mNlL-qjD&^g$=C=Y#2)=GfC%WfvR;4Ljt~bdavO^fr~3G*_=(00xRe&>OsCH_9cQYK-a7<9;IefM6^-yD#^n0TbVRV4BFAjg za7=*}3oMG&K;Uv6OHnVdB%aKeJ^A#gX%8BsDJ~1etuZ4tWY|gBSA#)RVFlfDCXzXU zb@B6~n+OHR$eWci;})G*zHUCX4MRaRqg6wTz(tC9Cz&>*%7hMjG02{dD6S^N8EcZj z(y0aJ#R9m7q-@>VmQJ_jazR{&8#G)mux4(-9?MP}PP8DpOLZO7))~t;3e;G8`V5DC z(tcwlb4zq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