X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.graphviz%2Fsrc%2Forg%2Fsimantics%2Fgraphviz%2Finternal%2Fprocess%2FCreateXDot.java;h=1b2323cd461b8d9e5ee6b76b4297d74caee1a20e;hb=214582bae00873fb90141b41d030e9c173a72e5f;hp=6a14465d877a155a00cbaf768fd70fa09a4d5284;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.graphviz/src/org/simantics/graphviz/internal/process/CreateXDot.java b/bundles/org.simantics.graphviz/src/org/simantics/graphviz/internal/process/CreateXDot.java index 6a14465d8..1b2323cd4 100644 --- a/bundles/org.simantics.graphviz/src/org/simantics/graphviz/internal/process/CreateXDot.java +++ b/bundles/org.simantics.graphviz/src/org/simantics/graphviz/internal/process/CreateXDot.java @@ -1,81 +1,81 @@ -package org.simantics.graphviz.internal.process; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintStream; - -import org.simantics.graphviz.Activator; -import org.simantics.graphviz.Graph; -import org.simantics.graphviz.Graphs; -import org.simantics.graphviz.continuation.ComputationThread; - -public class CreateXDot extends ComputationThread { - - Graph graph; - String algorithm; - - Process process; - - public CreateXDot(Graph graph, String algorithm) { - this.graph = graph; - this.algorithm = algorithm; - } - - @Override - protected void failWith(Exception exception) { - process.destroy(); - super.failWith(exception); - } - - @Override - public void run() { - try { - File DOT_EXE = Activator.getDotExe(); - process = new ProcessBuilder( - DOT_EXE.toString(), - "-Txdot", "-K" + algorithm) - .directory(DOT_EXE.getParentFile()) - .start(); - - // Writes output to the process - new Thread() { - public void run() { - PrintStream stream = new PrintStream(process.getOutputStream()); - graph.write(stream); - stream.close(); - } - }.start(); - - // Prints errors to stderr - new Thread() { - public void run() { - try { - InputStream errorStream = process.getErrorStream(); - while(true) { - int c = errorStream.read(); - if(c <= 0) - break; - System.err.print((char)c); - } - errorStream.close(); - } catch(IOException e) { - e.printStackTrace(); - } - } - }.start(); - - InputStream inputStream = process.getInputStream(); - byte[] buffer = Graphs.read(inputStream); - inputStream.close(); - - //System.out.println(new String(buffer)); - if(!isDone()) - doneWith(Graphs.parse(new ByteArrayInputStream(buffer))); - } catch(Exception e) { - failWith(e); - } - } - -} +package org.simantics.graphviz.internal.process; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; + +import org.simantics.graphviz.Activator; +import org.simantics.graphviz.Graph; +import org.simantics.graphviz.Graphs; +import org.simantics.graphviz.continuation.ComputationThread; + +public class CreateXDot extends ComputationThread { + + Graph graph; + String algorithm; + + Process process; + + public CreateXDot(Graph graph, String algorithm) { + this.graph = graph; + this.algorithm = algorithm; + } + + @Override + protected void failWith(Exception exception) { + process.destroy(); + super.failWith(exception); + } + + @Override + public void run() { + try { + File DOT_EXE = Activator.getDotExe(); + process = new ProcessBuilder( + DOT_EXE.toString(), + "-Txdot", "-K" + algorithm) + .directory(DOT_EXE.getParentFile()) + .start(); + + // Writes output to the process + new Thread() { + public void run() { + PrintStream stream = new PrintStream(process.getOutputStream()); + graph.write(stream); + stream.close(); + } + }.start(); + + // Prints errors to stderr + new Thread() { + public void run() { + try { + InputStream errorStream = process.getErrorStream(); + while(true) { + int c = errorStream.read(); + if(c <= 0) + break; + System.err.print((char)c); + } + errorStream.close(); + } catch(IOException e) { + e.printStackTrace(); + } + } + }.start(); + + InputStream inputStream = process.getInputStream(); + byte[] buffer = Graphs.read(inputStream); + inputStream.close(); + + //System.out.println(new String(buffer)); + if(!isDone()) + doneWith(Graphs.parse(new ByteArrayInputStream(buffer))); + } catch(Exception e) { + failWith(e); + } + } + +}