All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.io.github.moonlightsuite.moonlight.util.ObjectSerializer Maven / Gradle / Ivy

Go to download

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();
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy