use of com.solinia.solinia.Models.SoliniaZone in project solinia3-core by mixxit.
the class JsonZoneRepository method reload.
@Override
public void reload() {
List<SoliniaZone> file = new ArrayList<SoliniaZone>();
try {
Gson gson = new Gson();
BufferedReader br = new BufferedReader(new FileReader(filePath));
file = gson.fromJson(br, new TypeToken<List<SoliniaZone>>() {
}.getType());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Zones.clear();
for (SoliniaZone i : file) {
Zones.put(i.getId(), i);
}
System.out.println("Reloaded " + Zones.size() + " Zones");
}
use of com.solinia.solinia.Models.SoliniaZone in project solinia3-core by mixxit.
the class JsonZoneRepository method commit.
@Override
public void commit() {
// TODO Auto-generated method stub
GsonBuilder gsonbuilder = new GsonBuilder();
// gsonbuilder.setPrettyPrinting();
Gson gson = gsonbuilder.create();
String jsonOutput = gson.toJson(Zones.values(), new TypeToken<List<SoliniaZone>>() {
}.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 " + Zones.size() + " Zones");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations