Home > Object Persistency API > API Reference > SDF and SDML
For both XML and binary serialisation corresponding sources and sinks for the Streaming API are provided. They are called SDFCoder and SDFDecoder for the binary serialisation and SDMLCoder and SDMLDecoder for the XML serialisation. The classes are part of the Core project and filed in the package org.oomega.codec.
Binary serialisation (SDFCoder / SDFDecoder)
package org.oomega.codec; public class SDFCoder implements EOOutputStream<EntityObject> { public SDFCoder(OutputStream outStream) {} public SDFCoder(OutputStream outStream, String infoText) {} }
package org.oomega.codec; public class SDFDecoder extends AbstractDecoder<EntityObject> implements EOInputStream<EntityObject> { public SDFDecoder(InputStream inStream, ClassDirectory classDirectory) {} }
XML serialisation (SDMLCoder / SDMLDecoder)
package org.oomega.codec; public class SDMLCoder implements EOOutputStream<EntityObject> { public SDMLCoder(OutputStream outStream) {} }
package org.oomega.codec; public class SDMLDecoder extends AbstractDecoder<EntityObject> implements EOInputStream<EntityObject> { public SDMLDecoder(InputStream inStream, ClassDirectory classDirectory) {} public SDMLDecoder(InputStream inStream, ClassDirectory classDirectory, boolean ignoreInvalidTags) {} }
Examples
The use of these classes is best shown with a few examples. Prior to reading this, you should be already familiar with chapter Streaming.
Let's serialise all persons stored in the entity object container.
EOInputStream<EntityObject> in = new EOISFilter<EntityObject>(eocSession.getEOInputStream(), instance(Person.CID), eocSession); EOOutputStream<EntityObject> out = new SDFCoder(new FileOutputStream("build/output/demo-lessons/persons.sdf")); new ActivePipe<EntityObject>(out,in).run(); out.close();
To convert from the binary to the XML format, just connect the appropriate coder and decoder with an active pipe.
in = new SDFDecoder(new FileInputStream("build/output/demo-lessons/persons.sdf"), eocSession.getEOC().getClassDirectory()); out = new SDMLCoder(new FileOutputStream("build/output/demo-lessons/persons.xml")); new ActivePipe<EntityObject>(out,in).run(); out.close();
Now you can read the serialised persons into a new container.
EOContainerSession newEOCSession = MemoryEOC.createEOC(110).getSession(); new Gateway(newEocSession).loadSDFResource("demo.metamodel.sdf"); in = new SDMLDecoder(new FileInputStream("build/output/demo-lessons/persons.xml"), eocSession.getEOC().getClassDirectory()); out = newEOCSession.getEOOutputStream(); new ActivePipe<EntityObject>(out,in).run(); out.close();
Next chapter: Query Language