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

org.deeplearning4j.util.SerializationUtils Maven / Gradle / Ivy

There is a newer version: 1.0.0-M2.1
Show newest version
package org.deeplearning4j.util;

import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import org.apache.commons.io.FileUtils;

public class SerializationUtils {

	@SuppressWarnings("unchecked")
	public static  T readObject(File file) {
		try {
			ObjectInputStream ois = new ObjectInputStream(FileUtils.openInputStream(file));
			return (T) ois.readObject();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		
	}

	
	public static void saveObject(Object toSave,File saveTo) {
		try {
			ObjectOutputStream os = new ObjectOutputStream(FileUtils.openOutputStream(saveTo));
			os.writeObject(toSave);
			os.flush();
			os.close();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy