From 440bdecaea7ac47e3be2b370822644e1911e101b Mon Sep 17 00:00:00 2001 From: Bill Kuker Date: Thu, 11 Nov 2010 21:10:44 +0000 Subject: [PATCH] initial fuel IO --- .../rocketry/motorsim/io/MotorIO.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/com/billkuker/rocketry/motorsim/io/MotorIO.java b/src/com/billkuker/rocketry/motorsim/io/MotorIO.java index c784f0e..f2ce917 100644 --- a/src/com/billkuker/rocketry/motorsim/io/MotorIO.java +++ b/src/com/billkuker/rocketry/motorsim/io/MotorIO.java @@ -99,7 +99,6 @@ public class MotorIO { } - @SuppressWarnings("deprecation") private static XStream getXStream(){ @@ -111,6 +110,33 @@ public class MotorIO { return xstream; } + @SuppressWarnings("deprecation") + private static XStream getFuelXStream(){ + XStream xstream = new XStream(); + xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES); + xstream.registerConverter(new AmountConverter()); + xstream.registerConverter(new JavaBeanConverter(xstream.getClassMapper(), "class"), -20); + return xstream; + } + + public static void writeFuel(Fuel f, OutputStream os) throws IOException{ + ObjectOutputStream out = getFuelXStream().createObjectOutputStream(os); + out.writeObject(f); + out.close(); + os.flush(); + } + + public static Fuel readFuel(InputStream is) throws IOException{ + ObjectInputStream in = getFuelXStream().createObjectInputStream(is); + Fuel f; + try { + f = (Fuel)in.readObject(); + } catch (ClassNotFoundException e) { + throw new IOException("Class not found", e); + } + return f; + } + public static void writeMotor(Motor m, OutputStream os) throws IOException{ ObjectOutputStream out = getXStream().createObjectOutputStream(os); out.writeObject(m); -- 2.39.5