summaryrefslogtreecommitdiff
path: root/src/com/redstoner/misc/JsonManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/redstoner/misc/JsonManager.java')
-rw-r--r--src/com/redstoner/misc/JsonManager.java76
1 files changed, 48 insertions, 28 deletions
diff --git a/src/com/redstoner/misc/JsonManager.java b/src/com/redstoner/misc/JsonManager.java
index 998d137..cad716c 100644
--- a/src/com/redstoner/misc/JsonManager.java
+++ b/src/com/redstoner/misc/JsonManager.java
@@ -55,25 +55,35 @@ public class JsonManager
@Override
public void run()
{
- if (destination.exists())
- destination.delete();
- else if (!destination.getParentFile().exists())
- destination.getParentFile().mkdirs();
- try
- {
- destination.createNewFile();
- FileWriter writer = new FileWriter(destination);
- object.writeJSONString(writer);
- writer.flush();
- writer.close();
- }
- catch (IOException e)
- {}
+ saveSync(object, destination);
}
});
t.start();
}
+ /** Saves a JSONObject to a file. Will create the necessary FileStructure like folders and the file itself.</br>
+ * Note that this operation will be run on the same thread that you are calling it from!
+ *
+ * @param object the JSONObject to save.
+ * @param destination the file to write to. */
+ public static void saveSync(JSONObject object, File destination)
+ {
+ if (destination.exists())
+ destination.delete();
+ else if (!destination.getParentFile().exists())
+ destination.getParentFile().mkdirs();
+ try
+ {
+ destination.createNewFile();
+ FileWriter writer = new FileWriter(destination);
+ object.writeJSONString(writer);
+ writer.flush();
+ writer.close();
+ }
+ catch (IOException e)
+ {}
+ }
+
/** Loads a JSONArray from a file.
*
* @param source the file to load from.
@@ -106,22 +116,32 @@ public class JsonManager
@Override
public void run()
{
- if (destination.exists())
- destination.delete();
- else if (!destination.getParentFile().exists())
- destination.getParentFile().mkdirs();
- try
- {
- destination.createNewFile();
- FileWriter writer = new FileWriter(destination);
- array.writeJSONString(writer);
- writer.flush();
- writer.close();
- }
- catch (IOException e)
- {}
+ saveSync(array, destination);
}
});
t.start();
}
+
+ /** Saves a JSONArray to a file. Will create the necessary FileStructure like folders and the file itself.</br>
+ * Note that this operation will be run on the same thread that you are calling it from!
+ *
+ * @param object the JSONArray to save.
+ * @param destination the file to write to. */
+ public static void saveSync(JSONArray array, File destination)
+ {
+ if (destination.exists())
+ destination.delete();
+ else if (!destination.getParentFile().exists())
+ destination.getParentFile().mkdirs();
+ try
+ {
+ destination.createNewFile();
+ FileWriter writer = new FileWriter(destination);
+ array.writeJSONString(writer);
+ writer.flush();
+ writer.close();
+ }
+ catch (IOException e)
+ {}
+ }
}