| 120 | } |
| 121 | |
| 122 | public void dump(Graph<N> graph, File output) { |
| 123 | try (PrintStream out = new PrintStream(new FileOutputStream(output))) { |
| 124 | this.out = out; |
| 125 | // dump starts |
| 126 | out.println("digraph G {"); |
| 127 | // dump global node attributes |
| 128 | out.printf("%snode [%s];%n", INDENT, globalNodeAttrs); |
| 129 | // dump global edge attributes |
| 130 | out.printf("%sedge [%s];%n", INDENT, globalEdgeAttrs); |
| 131 | // dump nodes |
| 132 | graph.forEach(this::dumpNode); |
| 133 | // dump edges |
| 134 | graph.forEach(n -> graph.getOutEdgesOf(n).forEach(this::dumpEdge)); |
| 135 | // dump ends |
| 136 | out.println("}"); |
| 137 | } catch (FileNotFoundException e) { |
| 138 | logger.warn("Failed to dump graph to {}", output.getAbsolutePath(), e); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | private void dumpNode(N node) { |
| 143 | dumpElement(node, this::nodeToString, nodeLabeler, nodeAttributer); |