@@ -0,0 +1,2040 @@
+package org.loklak.tools;%0A%0Aimport java.io.File;%0Aimport java.io.FileReader;%0Aimport java.io.FileWriter;%0Aimport java.io.IOException;%0Aimport java.util.Collection;%0Aimport java.util.Map;%0A%0Aimport org.json.JSONException;%0Aimport org.json.JSONObject;%0Aimport org.json.JSONTokener;%0A%0A/**%0A * This extends JSONObject to be a file which gets loaded and written to disk%0A *%0A */%0Apublic class JSONFile extends JSONObject %7B%0A%09%0A%09private File file;%0A%0A%09public JSONFile(File file) throws IOException%7B%0A%09%09super();%0A%09%09this.file = file;%0A%09%09if(this.file.exists())%7B%0A%09%09%09JSONTokener tokener;%0A%09%09%09tokener = new JSONTokener(new FileReader(file));%0A%09%09%09putAll(new JSONObject(tokener));%0A%09%09%7D%0A%09%09else%7B%0A%09%09%09this.file.createNewFile();%0A%09%09%7D%0A%09%7D%0A%09%0A%09private void writeFile() throws JSONException%7B%0A%09%09FileWriter writer;%0A%09%09try %7B%0A%09%09%09writer = new FileWriter(file);%0A%09%09%09writer.write(this.toString());%0A%09%09%09writer.close();%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09throw new JSONException(e.getMessage());%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public JSONObject put(String key, boolean value) throws JSONException %7B%0A%09%09this.put(key, value);%0A%09%09writeFile();%0A%09%09return this;%0A%09%7D%0A%09%0A%09@Override%0A%09public JSONObject put(String key, double value) throws JSONException %7B%0A%09%09this.put(key, value);%0A%09%09writeFile();%0A%09%09return this;%0A%09%7D%0A%09%0A%09@Override%0A%09public JSONObject put(String key, Collection%3C?%3E value) throws JSONException %7B%0A%09%09this.put(key, value);%0A%09%09writeFile();%0A%09%09return this;%0A%09%7D%0A%09%0A%09@Override%0A%09public JSONObject put(String key, int value) throws JSONException %7B%0A%09%09this.put(key, value);%0A%09%09writeFile();%0A%09%09return this;%0A%09%7D%0A%09%0A%09@Override%0A%09public JSONObject put(String key, long value) throws JSONException %7B%0A%09%09this.put(key, value);%0A%09%09writeFile();%0A%09%09return this;%0A%09%7D%0A%09%0A%09@Override%0A%09public JSONObject put(String key, Map%3C?, ?%3E value) throws JSONException %7B%0A%09%09this.put(key, value);%0A%09%09writeFile();%0A%09%09return this;%0A%09%7D%0A%09%0A%09@Override%0A%09public JSONObject put(String key, Object value) throws JSONException %7B%0A%09%09this.put(key, value);%0A%09%09writeFile();%0A%09%09return this;%0A%09%7D%0A%09%0A%09@Override%0A%09public Object remove(String key) %7B%0A%09%09this.remove(key);%0A%09%09writeFile();%0A%09%09return this;%0A%09%7D%0A%7D%0A

Add persistent json storage JSONFile