main.io.github.moonlightsuite.moonlight.util.ObjectSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of moonlight-engine Show documentation
Show all versions of moonlight-engine Show documentation
MoonLight is a light-weight Java-tool for monitoring temporal, spatial and spatio-temporal properties of distributed complex systems, such as Cyber-Physical Systems and Collective Adaptive Systems.
The newest version!
package io.github.moonlightsuite.moonlight.util;
import java.io.*;
public class ObjectSerializer {
private ObjectSerializer() {
//utility class
}
public static void serialize(Object object, String path) throws IOException {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File(path)))) {
oos.writeObject(object);
}
}
public static T deserialize(String objectPath, Class objectType) throws IOException, ClassNotFoundException {
try (ObjectInputStream iis = new ObjectInputStream(new FileInputStream(objectPath))) {
return (T) iis.readObject();
}
}
}