use of com.solinia.solinia.Factories.ISoliniaSpawnGroupTypeAdapterFactory in project solinia3-core by mixxit.
the class JsonSpawnGroupRepository method commit.
@Override
public void commit() {
// TODO Auto-generated method stub
GsonBuilder gsonbuilder = new GsonBuilder();
// gsonbuilder.setPrettyPrinting();
gsonbuilder.registerTypeAdapterFactory(new ISoliniaSpawnGroupTypeAdapterFactory(SoliniaSpawnGroup.class));
Gson gson = gsonbuilder.create();
String jsonOutput = gson.toJson(spawngroups.values(), new TypeToken<List<SoliniaSpawnGroup>>() {
}.getType());
try {
File file = new File(filePath);
if (!file.exists())
file.createNewFile();
FileOutputStream fileOut = new FileOutputStream(file);
OutputStreamWriter outWriter = new OutputStreamWriter(fileOut);
outWriter.append(jsonOutput);
outWriter.close();
fileOut.close();
System.out.println("Commited " + spawngroups.size() + " spawngroups");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of com.solinia.solinia.Factories.ISoliniaSpawnGroupTypeAdapterFactory in project solinia3-core by mixxit.
the class JsonSpawnGroupRepository method reload.
@Override
public void reload() {
List<ISoliniaSpawnGroup> file = new ArrayList<ISoliniaSpawnGroup>();
try {
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.registerTypeAdapterFactory(new ISoliniaSpawnGroupTypeAdapterFactory(SoliniaSpawnGroup.class));
Gson gson = gsonbuilder.create();
BufferedReader br = new BufferedReader(new FileReader(filePath));
file = gson.fromJson(br, new TypeToken<List<SoliniaSpawnGroup>>() {
}.getType());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
spawngroups.clear();
for (ISoliniaSpawnGroup i : file) {
spawngroups.put(i.getId(), i);
}
System.out.println("Reloaded " + spawngroups.size() + " spawngroups");
}
Aggregations