modifiers) {
155 | String methodModifier = "";
156 | if (modifiers.contains(ModifierKind.PUBLIC)) {
157 | methodModifier += ModifierKind.PUBLIC + " ";
158 | }
159 | if (modifiers.contains(ModifierKind.PROTECTED)) {
160 | methodModifier += ModifierKind.PROTECTED + " ";
161 | }
162 | if (modifiers.contains(ModifierKind.PRIVATE)) {
163 | methodModifier += ModifierKind.PROTECTED + " ";
164 | }
165 | if (modifiers.contains(ModifierKind.ABSTRACT)) {
166 | methodModifier += ModifierKind.ABSTRACT + " ";
167 | }
168 | if (modifiers.contains(ModifierKind.STATIC)) {
169 | methodModifier += ModifierKind.STATIC + " ";
170 | }
171 | if (modifiers.contains(ModifierKind.FINAL)) {
172 | methodModifier += ModifierKind.FINAL + " ";
173 | }
174 | if (modifiers.contains(ModifierKind.SYNCHRONIZED)) {
175 | methodModifier += ModifierKind.SYNCHRONIZED + " ";
176 | }
177 | if (modifiers.contains(ModifierKind.NATIVE)) {
178 | methodModifier += ModifierKind.SYNCHRONIZED + " ";
179 | }
180 | if (modifiers.contains(ModifierKind.STRICTFP)) {
181 | methodModifier += ModifierKind.STRICTFP + " ";
182 | }
183 | if (modifiers.contains(ModifierKind.TRANSIENT)) {
184 | methodModifier += ModifierKind.TRANSIENT + " ";
185 | }
186 | if (modifiers.contains(ModifierKind.VOLATILE)) {
187 | methodModifier += ModifierKind.VOLATILE + " ";
188 | }
189 | return methodModifier;
190 | }
191 | }
--------------------------------------------------------------------------------
/src/main/java/org/nhjclxc/graphviz/GraphvizAssistant.java:
--------------------------------------------------------------------------------
1 | package org.nhjclxc.graphviz;
2 |
3 | import java.io.*;
4 |
5 | /**
6 | * Graphviz图片生成助手
7 | *
8 | * @author LuoXianchao
9 | * @since 2023/10/30 23:36
10 | */
11 | public class GraphvizAssistant {
12 |
13 | /**
14 | * The image size in dpi. 96 dpi is normal size. Higher values are 10% higher each. Lower values
15 | * 10% lower each.
16 | *
17 | * dpi patch by Peter Mueller
18 | */
19 | private static final int[] dpiSizes = {46, 51, 57, 63, 70, 78, 86, 96, 106, 116, 128, 141, 155, 170, 187, 206, 226, 249};
20 |
21 | /**
22 | * Define the index in the image size array.
23 | */
24 | private static final int currentDpiPos = 14;
25 |
26 | /**
27 | * Graphviz软件安装路径
28 | */
29 | private static final String executable = "D:\\develop\\Graphviz\\bin\\dot.exe";
30 |
31 |
32 | /**
33 | * 从dot语言生成image
34 | * It will call the external dot program, and return the image in binary format.
35 | *
36 | * @param dotFile Source of the graph (in dot language).
37 | * @param imageType Type of the output image to be produced, e.g.: gif, dot, fig, pdf, ps, svg, png.
38 | * @param representationType Type of how you want to represent the graph:
39 | *
40 | * - dot
41 | * - neato
42 | * - fdp
43 | * - sfdp
44 | * - twopi
45 | * - circo
46 | *
47 | * @author 罗贤超
48 | */
49 | public static void createImage(final File dotFile, final String imageType, final String representationType) {
50 | try {
51 | String filePathPerfix = getFilePathPerfix(dotFile.getAbsolutePath());
52 | File imageFile = new File(filePathPerfix + "." + imageType);
53 |
54 | final Runtime rt = Runtime.getRuntime();
55 | final String[] args = {executable, "-T" + imageType, "-K" + representationType, "-Gdpi=" + dpiSizes[currentDpiPos],
56 | dotFile.getAbsolutePath(), "-o", imageFile.getAbsolutePath()};
57 | final Process process = rt.exec(args);
58 | process.waitFor();
59 |
60 | // System.out.println("文件写入成功");
61 | } catch (final IOException | InterruptedException e) {
62 | e.printStackTrace();
63 | }
64 |
65 | }
66 |
67 | /**
68 | * 获取文件路径前缀:path\filename,没有扩展名
69 | */
70 | private static String getFilePathPerfix(String fileName) {
71 | int dotIndex = fileName.lastIndexOf(".");
72 | if (dotIndex != -1) {
73 | return fileName.substring(0, dotIndex);
74 | }
75 | return "";
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------