X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2FGraphCompiler.java;h=c1d9609e712b056a2313faebdde51b92a37cb9d6;hb=refs%2Fchanges%2F50%2F1850%2F1;hp=26663b08a2a5f288e9f38753ff53162045a82c02;hpb=aab6399f20c07b61a0dbf9614614f44a2e0ea325;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/GraphCompiler.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/GraphCompiler.java index 26663b08a..c1d9609e7 100644 --- a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/GraphCompiler.java +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/GraphCompiler.java @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Formatter; import java.util.Locale; +import java.util.TreeMap; import org.simantics.databoard.Bindings; import org.simantics.databoard.Files; @@ -56,23 +57,29 @@ public class GraphCompiler { } public static TransferableGraph1 read(InputStream stream) throws AdaptException, IOException { - DataContainer container = DataContainers.readFile(new DataInputStream(stream)); - stream.close(); - return (TransferableGraph1)container.content.getValue(TransferableGraph1.BINDING); + try (InputStream in = stream) { + DataContainer container = DataContainers.readFile(new DataInputStream(stream)); + return (TransferableGraph1)container.content.getValue(TransferableGraph1.BINDING); + } } public static InputStream write(TransferableGraph1 tg) throws BindingException, IOException { Binding binding = TransferableGraph1.BINDING; int hashCode = binding.hashValue(tg); - tg.extensions.put(Extensions.CACHED_HASHCODE, new Variant(Bindings.INTEGER, hashCode)); - try { - byte[] buffer = DataContainers.writeFile( - new DataContainer("graph", 1, new Variant(TransferableGraph1.BINDING, tg)) - ); - return new ByteArrayInputStream(buffer); - } finally { - tg.extensions.remove(Extensions.CACHED_HASHCODE); - } + TreeMap metadata = new TreeMap<>(); + metadata.put(Extensions.CACHED_HASHCODE, new Variant(Bindings.INTEGER, hashCode)); + byte[] buffer = DataContainers.writeFile( + new DataContainer("graph", 1, metadata, new Variant(binding, tg)) + ); + return new ByteArrayInputStream(buffer); + } + + public static void write(File file, TransferableGraph1 tg) throws BindingException, IOException { + Binding binding = TransferableGraph1.BINDING; + int hashCode = binding.hashValue(tg); + TreeMap metadata = new TreeMap<>(); + metadata.put(Extensions.CACHED_HASHCODE, new Variant(Bindings.INTEGER, hashCode)); + DataContainers.writeFile(file, new DataContainer("graph", 1, metadata, new Variant(binding, tg))); } public static CompilationResult compile( @@ -81,7 +88,7 @@ public class GraphCompiler { Collection dependencies, ExternalFileLoader fileLoader, GraphCompilerPreferences preferences) { - out.println(preferences); + //out.println(preferences); Collection errors = new ArrayList(); GraphStore store = new GraphStore(); @@ -198,11 +205,11 @@ public class GraphCompiler { } private static void run(Runnable runnable) { - long beginTime = System.nanoTime(); + //long beginTime = System.nanoTime(); runnable.run(); - long endTime = System.nanoTime(); + //long endTime = System.nanoTime(); - reportTime(runnable.getClass().getSimpleName(), beginTime, endTime); + //reportTime(runnable.getClass().getSimpleName(), beginTime, endTime); } public static void reportTime(String taskName, long beginTime, long endTime) {