1 package org.simantics.graphviz.internal.process;
3 import java.io.ByteArrayInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.io.PrintStream;
9 import org.simantics.graphviz.Activator;
10 import org.simantics.graphviz.Graph;
11 import org.simantics.graphviz.Graphs;
12 import org.simantics.graphviz.continuation.ComputationThread;
14 public class CreateXDot extends ComputationThread<Graph> {
21 public CreateXDot(Graph graph, String algorithm) {
23 this.algorithm = algorithm;
27 protected void failWith(Exception exception) {
29 super.failWith(exception);
35 File DOT_EXE = Activator.getDotExe();
36 process = new ProcessBuilder(
38 "-Txdot", "-K" + algorithm)
39 .directory(DOT_EXE.getParentFile())
42 // Writes output to the process
45 PrintStream stream = new PrintStream(process.getOutputStream());
51 // Prints errors to stderr
55 InputStream errorStream = process.getErrorStream();
57 int c = errorStream.read();
60 System.err.print((char)c);
63 } catch(IOException e) {
69 InputStream inputStream = process.getInputStream();
70 byte[] buffer = Graphs.read(inputStream);
73 //System.out.println(new String(buffer));
75 doneWith(Graphs.parse(new ByteArrayInputStream(buffer)));
76 } catch(Exception e) {