/*
- * Copyright (c) 2017. Developed by Hedgecode.
+ * Copyright (c) 2017-2020. Developed by Hedgecode.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.Serializable;
import com.google.gson.Gson;
getClass().getSimpleName() + JSON_EXT
).getFile()
);
- private final File serFile =
+ private final File serializeFile =
new File(
jsonFile.getParent() + File.separator
+ getClass().getSimpleName() + SERIALIZE_EXT
return sb.toString();
}
- protected void serialize(JsonSerializable jsonObject) throws IOException {
+ protected void verifySerialize(Serializable serializeObject) throws IOException {
+ if (!serializeFile.exists()) {
+ serialize(serializeObject);
+ }
+ }
+
+ protected void serialize(Serializable serializeObject) throws IOException {
try (ObjectOutputStream oos =
new ObjectOutputStream(
new FileOutputStream(
- serFile.getAbsolutePath()
+ serializeFile.getAbsolutePath()
)
)
) {
- oos.writeObject(jsonObject);
+ oos.writeObject(serializeObject);
}
}
- protected JsonSerializable deserialize() throws IOException, ClassNotFoundException {
- JsonSerializable jsonObject;
+ protected Serializable deserialize() throws IOException, ClassNotFoundException {
+ Serializable deserializeObject;
try (ObjectInputStream ois =
new ObjectInputStream(
new FileInputStream(
- serFile.getAbsolutePath()
+ serializeFile.getAbsolutePath()
)
)
) {
- jsonObject = (JsonSerializable) ois.readObject();
+ deserializeObject = (Serializable) ois.readObject();
}
- return jsonObject;
+ return deserializeObject;
}
}