Better handle of File reading / Input Streams

This commit is contained in:
Max Dor
2019-01-11 23:02:57 +01:00
parent 83377ebee0
commit c6b8f7d48e
8 changed files with 79 additions and 46 deletions

View File

@@ -37,8 +37,10 @@ public class YamlConfigLoader {
rep.getPropertyUtils().setAllowReadOnlyProperties(true);
rep.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(new Constructor(MxisdConfig.class), rep);
Object o = yaml.load(new FileInputStream(path));
return GsonUtil.get().fromJson(GsonUtil.get().toJson(o), MxisdConfig.class);
try (FileInputStream is = new FileInputStream(path)) {
Object o = yaml.load(is);
return GsonUtil.get().fromJson(GsonUtil.get().toJson(o), MxisdConfig.class);
}
}
public static Optional<MxisdConfig> tryLoadFromFile(String path) {