From: Tuukka Lehtonen Date: Fri, 9 Feb 2018 08:26:29 +0000 (+0200) Subject: Added more TransferableGraphs.writeTransferableGraph methods X-Git-Tag: v1.43.0~136^2~595 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F39%2F1439%2F1;p=simantics%2Fplatform.git Added more TransferableGraphs.writeTransferableGraph methods * writeTransferableGraph(RequestProcessor, TransferableGraphSource, File, TGStatusMonitor) writes the specified TG source into the specified file as a variant (i.e. datatype + data) * writeTransferableGraphVariant(RequestProcessor, TransferableGraphSource, RandomAccessBinary, TGStatusMonitor) writes the specified TG source into the specified output binary file as a variant (i.e. datatype + data) refs #7758 Change-Id: Ia50a1ce9c461681ac10be73674fa0e5e9c22b404 --- diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java index 67689ff46..0841e1455 100644 --- a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java +++ b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java @@ -440,15 +440,23 @@ public class TransferableGraphs { } public static void writeTransferableGraph(RequestProcessor processor, String format, int version, TreeMap metadata, TransferableGraphSource source, File target, TGStatusMonitor monitor) throws Exception { - final Serializer datatypeSerializer = Bindings.getSerializerUnchecked(Datatype.class); try (RandomAccessBinary out = new BinaryFile(target, 128*1024)) { - DataContainer container = new DataContainer(format, version, metadata, null); - DataContainers.writeHeader(out, container); - datatypeSerializer.serialize((DataOutput) out, Datatypes.getDatatypeUnchecked(TransferableGraph1.class)); - writeTransferableGraph(processor, source, out, monitor); + DataContainers.writeHeader(out, new DataContainer(format, version, metadata, null)); + writeTransferableGraphVariant(processor, source, out, monitor); } } + public static void writeTransferableGraph(RequestProcessor processor, TransferableGraphSource source, File target, TGStatusMonitor monitor) throws Exception { + try (RandomAccessBinary out = new BinaryFile(target, 128*1024)) { + writeTransferableGraphVariant(processor, source, out, monitor); + } + } + + public static void writeTransferableGraphVariant(RequestProcessor processor, TransferableGraphSource source, RandomAccessBinary out, TGStatusMonitor monitor) throws Exception { + Bindings.getSerializerUnchecked(Datatype.class).serialize(out, Datatypes.getDatatypeUnchecked(TransferableGraph1.class)); + writeTransferableGraph(processor, source, out, monitor); + } + private static TGStatusMonitor safeMonitor(TGStatusMonitor mon) { return mon == null ? TGStatusMonitor.NULL_MONITOR : mon; }