ServerPropertyFile now serializes with pretty printing
This commit is contained in:
parent
489b81e55f
commit
ce4f756446
@ -8,10 +8,13 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
|
||||||
public class ServerPropertyFile {
|
public class ServerPropertyFile {
|
||||||
|
|
||||||
|
private static final Gson SERIALIZER = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
|
||||||
private transient File file;
|
private transient File file;
|
||||||
|
|
||||||
private String name = "default_name";
|
private String name = "default_name";
|
||||||
@ -36,7 +39,7 @@ public class ServerPropertyFile {
|
|||||||
public boolean loadFromFile() {
|
public boolean loadFromFile() {
|
||||||
try (BufferedReader in = new BufferedReader(new FileReader(file))) {
|
try (BufferedReader in = new BufferedReader(new FileReader(file))) {
|
||||||
|
|
||||||
ServerPropertyFile dataFile = new Gson().fromJson(in, getClass());
|
ServerPropertyFile dataFile = SERIALIZER.fromJson(in, getClass());
|
||||||
|
|
||||||
name = dataFile.name;
|
name = dataFile.name;
|
||||||
memory = dataFile.memory;
|
memory = dataFile.memory;
|
||||||
@ -58,10 +61,8 @@ public class ServerPropertyFile {
|
|||||||
|
|
||||||
public boolean save() {
|
public boolean save() {
|
||||||
try (BufferedWriter out = new BufferedWriter(new FileWriter(file, false))) {
|
try (BufferedWriter out = new BufferedWriter(new FileWriter(file, false))) {
|
||||||
|
SERIALIZER.toJson(this, out);
|
||||||
new Gson().toJson(this, out);
|
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.severe(e);
|
Log.severe(e);
|
||||||
|
Loading…
Reference in New Issue
Block a user