0

Made file saving run async

This commit is contained in:
Pepich 2017-02-01 17:11:16 +01:00
parent c89b43d247
commit 0e46725dab

View File

@ -15,7 +15,7 @@ import com.redstoner.annotations.Version;
/** This class provides simple JSON handling, like storing and loading from and to files. /** This class provides simple JSON handling, like storing and loading from and to files.
* *
* @author Pepich */ * @author Pepich */
@Version(major = 1, minor = 0, revision = 0, compatible = -1) @Version(major = 1, minor = 0, revision = 1, compatible = -1)
public class JsonManager public class JsonManager
{ {
private JsonManager() private JsonManager()
@ -43,11 +43,17 @@ public class JsonManager
return null; return null;
} }
/** Saves a JSONObject to a file. Will create the necessary FileStructure like folders and the file itself. /** 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 a different thread and you do not need to take care of that yourself.
* *
* @param object the JSONObject to save. * @param object the JSONObject to save.
* @param destination the file to write to. */ * @param destination the file to write to. */
public static void save(JSONObject object, File destination) public static void save(JSONObject object, File destination)
{
Thread t = new Thread(new Runnable()
{
@Override
public void run()
{ {
if (destination.exists()) if (destination.exists())
destination.delete(); destination.delete();
@ -64,6 +70,9 @@ public class JsonManager
catch (IOException e) catch (IOException e)
{} {}
} }
});
t.start();
}
/** Loads a JSONArray from a file. /** Loads a JSONArray from a file.
* *
@ -85,11 +94,17 @@ public class JsonManager
return null; return null;
} }
/** Saves a JSONArray to a file. Will create the necessary FileStructure like folders and the file itself. /** 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 a different thread and you do not need to take care of that yourself.
* *
* @param object the JSONArray to save. * @param object the JSONArray to save.
* @param destination the file to write to. */ * @param destination the file to write to. */
public static void save(JSONArray array, File destination) public static void save(JSONArray array, File destination)
{
Thread t = new Thread(new Runnable()
{
@Override
public void run()
{ {
if (destination.exists()) if (destination.exists())
destination.delete(); destination.delete();
@ -106,4 +121,7 @@ public class JsonManager
catch (IOException e) catch (IOException e)
{} {}
} }
});
t.start();
}
} }