UTD
This commit is contained in:
40
.classpath
Normal file
40
.classpath
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
||||||
23
.project
Normal file
23
.project
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>JsonManager</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
6
.settings/org.eclipse.core.resources.prefs
Normal file
6
.settings/org.eclipse.core.resources.prefs
Normal file
@@ -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/<project>=UTF-8
|
||||||
8
.settings/org.eclipse.jdt.core.prefs
Normal file
8
.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -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
|
||||||
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
||||||
65
pom.xml
Normal file
65
pom.xml
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>eu.triler.code</groupId>
|
||||||
|
<artifactId>JsonManager</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<name>JsonManager</name>
|
||||||
|
<properties>
|
||||||
|
<java.version>11</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>TrilerGit</id>
|
||||||
|
<url>https://git.triler.eu/api/packages/TrilerCode/maven</url>
|
||||||
|
</repository>
|
||||||
|
</distributionManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.googlecode.json-simple</groupId>
|
||||||
|
<artifactId>json-simple</artifactId>
|
||||||
|
<version>1.1.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.9.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
99
src/main/java/eu/triler/code/JsonManager/JsonManager.java
Normal file
99
src/main/java/eu/triler/code/JsonManager/JsonManager.java
Normal file
@@ -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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
4
target/classes/META-INF/MANIFEST.MF
Normal file
4
target/classes/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Build-Jdk-Spec: 23
|
||||||
|
Created-By: Maven Integration for Eclipse
|
||||||
|
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>eu.triler.code</groupId>
|
||||||
|
<artifactId>JsonManager</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<name>JsonManager</name>
|
||||||
|
<properties>
|
||||||
|
<java.version>11</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>TrilerGit</id>
|
||||||
|
<url>https://git.triler.eu/api/packages/TrilerCode/maven</url>
|
||||||
|
</repository>
|
||||||
|
</distributionManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.googlecode.json-simple</groupId>
|
||||||
|
<artifactId>json-simple</artifactId>
|
||||||
|
<version>1.1.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.9.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
BIN
target/classes/eu/triler/code/JsonManager/JsonManager.class
Normal file
BIN
target/classes/eu/triler/code/JsonManager/JsonManager.class
Normal file
Binary file not shown.
Reference in New Issue
Block a user