From 362310157373eef80f49ea6023b1666b3883f4b1 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sun, 3 Nov 2019 16:39:58 +0100 Subject: Implement ZMI serialization --- src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java index a6b78da..5a560ae 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java @@ -24,12 +24,18 @@ package pl.edu.mimuw.cloudatlas.model; +import java.io.InputStream; +import java.io.OutputStream; import java.io.PrintStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map.Entry; +import com.esotericsoftware.kryo.Kryo; +import com.esotericsoftware.kryo.io.Input; +import com.esotericsoftware.kryo.io.Output; + /** * A zone management information object. This object is a single node in a zone hierarchy. It stores zone attributes as well as * references to its father and sons in the tree. @@ -163,4 +169,18 @@ public class ZMI implements Cloneable { public String toString() { return attributes.toString(); } + + public static ZMI deserialize(InputStream in) { + Kryo kryo = new Kryo(); + Input kryoInput = new Input(in); + ZMI zmi = kryo.readObject(kryoInput, ZMI.class); + return zmi; + } + + public void serialize(OutputStream out) { + Kryo kryo = new Kryo(); + Output kryoOut = new Output(out); + kryo.writeObject(kryoOut, this); + kryoOut.flush(); + } } -- cgit v1.2.3