Browse Source

03.04.2018 -- Fixed

master
Niklas H. 1 year ago
parent
commit
924fbb6f1c
5 changed files with 23 additions and 15 deletions
  1. +4
    -2
      config.conf
  2. +1
    -1
      pom.xml
  3. +16
    -7
      src/main/java/de/moddylp/simplecommentconfig/Config.java
  4. +1
    -4
      src/main/java/de/moddylp/simplecommentconfig/ConfigManager.java
  5. +1
    -1
      src/test/resources/test.yml

+ 4
- 2
config.conf View File

@@ -17,7 +17,7 @@ tollermainkey: 4444.0
tada2: 'tadavalue2'
tada3: false
tada4: true
tada5: 'adavalue5'
tada5: 'üöäöäöäööß'

#Lala Section
a2Section:
@@ -52,4 +52,6 @@ newtest:
#ICH bin ein ganz langer kommentar und mache jetzt alles kaputt damm damm dammmmmmmm. Aber villeicht auch nicht
lustig: 55555.0


tada22: 56.8
tada23: 23.0
tollermainkey: 4444.0

+ 1
- 1
pom.xml View File

@@ -6,7 +6,7 @@

<groupId>de.moddylp</groupId>
<artifactId>simplecommentconfig</artifactId>
<version>20180322</version>
<version>20180403</version>

<distributionManagement>
<repository>

+ 16
- 7
src/main/java/de/moddylp/simplecommentconfig/Config.java View File

@@ -1,6 +1,7 @@
package de.moddylp.simplecommentconfig;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.concurrent.atomic.AtomicReference;
@@ -12,7 +13,7 @@ import java.util.concurrent.atomic.AtomicReference;
public class Config {
private final String MAINSECTIONID = "<<!!!!>>";
private final String NEWLN = "\n";
private LinkedHashMap<String, String> comments = new LinkedHashMap<String, String>();
private LinkedHashMap<String, String> comments = new LinkedHashMap<>();
private LinkedHashMap<String, LinkedHashMap<String, Object>> sections = new LinkedHashMap<>();
private ArrayList<String> header = new ArrayList<>();
private File configfile;
@@ -27,14 +28,22 @@ public class Config {
return;
}
try {
parse(new BufferedReader(new FileReader(configfile)));
parse(new BufferedReader(new InputStreamReader(new FileInputStream(configfile), StandardCharsets.UTF_8)));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}

public void parseString(String string) {
parse(new BufferedReader(new StringReader(string)));
public void parseAndCopyConfigFile(File file) {
if (file == null) {
return;
}
try {
parse(new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)));
saveToFile();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}

private void parse(BufferedReader reader) {
@@ -73,8 +82,8 @@ public class Config {
return;
}
try {
PrintWriter writer = new PrintWriter(configfile, "UTF-8");
writer.println(returnConfigString());
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(configfile), StandardCharsets.UTF_8);
writer.write(returnConfigString());
writer.close();
} catch (Exception ex) {
ex.printStackTrace();
@@ -350,7 +359,7 @@ public class Config {
if (get(optionpath) == null) {
set(optionpath, value);
}
return value;
return get(optionpath);
}

public Object get(String optionpath, Object value, String comment) {

+ 1
- 4
src/main/java/de/moddylp/simplecommentconfig/ConfigManager.java View File

@@ -40,11 +40,8 @@ public class ConfigManager {
if (!configfile.exists()) {
throw new Exception("No File found in Ressources");
}
Config config = new Config(configfile);
config.reload();

Config finalconfiginst = getConfig(path);
finalconfiginst.parseString(config.returnConfigString());
finalconfiginst.parseAndCopyConfigFile(configfile);
finalconfiginst.saveToFile();

} catch (Exception ex) {

+ 1
- 1
src/test/resources/test.yml View File

@@ -16,7 +16,7 @@ tada23: 23
tada3: false
#Toller Wert
tada4: true
tada5: 'adavalue5'
tada5: 'üöäöäöäööß'

#Lala Section
a2Section:

Loading…
Cancel
Save