MCPcopy Create free account
hub / github.com/Neop/mudmap2 / writeListJSON

Method writeListJSON

src/main/java/mudmap2/backend/WorldFileList.java:246–289  ·  view source on GitHub ↗

Write JSON-formatted history file @param file

(File file)

Source from the content-addressed store, hash-verified

244 * @param file
245 */
246 private static void writeListJSON(File file){
247 if(!file.exists() || file.canWrite()){
248 BufferedWriter writer = null;
249
250 // create parent directories
251 File parentDir = file.getParentFile();
252 if(!parentDir.exists()){
253 parentDir.mkdirs();
254 }
255
256 try {
257 writer = new BufferedWriter(new FileWriter(file));
258 } catch (IOException ex) {
259 Logger.getLogger(WorldFileList.class.getName()).log(Level.WARNING, null, ex);
260 }
261
262 if(writer != null){
263 JSONObject jRoot = new JSONObject();
264
265 jRoot.put("ver", "" + FILE_VER_MAJOR + "." + FILE_VER_MINOR);
266
267 JSONArray jHistory = new JSONArray();
268 jRoot.put("history", jHistory);
269
270 for(WorldFileEntry entry: getEntries()){
271 JSONObject jElement = new JSONObject();
272 jHistory.put(jElement);
273
274 jElement.put("file", entry.getFile().getAbsoluteFile());
275 jElement.put("name", entry.getWorldName());
276 }
277
278 jRoot.write(writer, 4, 0);
279
280 try {
281 writer.close();
282 } catch (IOException ex) {
283 Logger.getLogger(WorldFileList.class.getName()).log(Level.SEVERE, null, ex);
284 }
285 }
286 } else {
287 System.err.println("Could not write file " + file.getAbsolutePath());
288 }
289 }
290
291 /**
292 * Read available worlds file (legacy)

Callers 1

writeMethod · 0.95

Calls 7

getEntriesMethod · 0.95
putMethod · 0.80
getWorldNameMethod · 0.80
writeMethod · 0.80
closeMethod · 0.80
getNameMethod · 0.45
getFileMethod · 0.45

Tested by

no test coverage detected