equal
deleted
inserted
replaced
25 package jdk.jfr.internal.dcmd; |
25 package jdk.jfr.internal.dcmd; |
26 |
26 |
27 import java.io.IOException; |
27 import java.io.IOException; |
28 import java.io.PrintWriter; |
28 import java.io.PrintWriter; |
29 import java.io.StringWriter; |
29 import java.io.StringWriter; |
|
30 import java.nio.file.Files; |
30 import java.nio.file.InvalidPathException; |
31 import java.nio.file.InvalidPathException; |
31 import java.nio.file.Path; |
32 import java.nio.file.Path; |
|
33 import java.nio.file.Paths; |
32 import java.time.Duration; |
34 import java.time.Duration; |
33 import java.util.ArrayList; |
35 import java.util.ArrayList; |
34 import java.util.Collections; |
36 import java.util.Collections; |
35 import java.util.Comparator; |
37 import java.util.Comparator; |
36 import java.util.List; |
38 import java.util.List; |
61 |
63 |
62 public final String getResult() { |
64 public final String getResult() { |
63 return result.toString(); |
65 return result.toString(); |
64 } |
66 } |
65 |
67 |
66 protected final SafePath resolvePath(String path, String errorMsg) throws DCmdException { |
68 protected final SafePath resolvePath(Recording recording, String filename) throws InvalidPathException { |
67 if (path == null) { |
69 if (filename == null) { |
68 return null; |
70 return makeGenerated(recording, Paths.get(".")); |
69 } |
71 } |
70 try { |
72 Path path = Paths.get(filename); |
71 return new SafePath(path); |
73 if (Files.isDirectory(path)) { |
72 } catch (InvalidPathException e) { |
74 return makeGenerated(recording, path); |
73 throw new DCmdException(e, errorMsg, ", invalid path \"" + path + "\"."); |
|
74 } |
75 } |
|
76 return new SafePath(path.toAbsolutePath().normalize()); |
|
77 } |
|
78 |
|
79 private SafePath makeGenerated(Recording recording, Path directory) { |
|
80 return new SafePath(directory.toAbsolutePath().resolve(Utils.makeFilename(recording)).normalize()); |
75 } |
81 } |
76 |
82 |
77 protected final Recording findRecording(String name) throws DCmdException { |
83 protected final Recording findRecording(String name) throws DCmdException { |
78 try { |
84 try { |
79 return findRecordingById(Integer.parseInt(name)); |
85 return findRecordingById(Integer.parseInt(name)); |
81 // User specified a name, not an id. |
87 // User specified a name, not an id. |
82 return findRecordingByName(name); |
88 return findRecordingByName(name); |
83 } |
89 } |
84 } |
90 } |
85 |
91 |
86 protected final void reportOperationComplete(String actionPrefix, Recording r, SafePath file) { |
92 protected final void reportOperationComplete(String actionPrefix, String name, SafePath file) { |
87 print(actionPrefix); |
93 print(actionPrefix); |
88 print(" recording "); |
94 print(" recording"); |
89 print("\"" + r.getName() + "\""); |
95 if (name != null) { |
|
96 print(" \"" + name + "\""); |
|
97 } |
90 if (file != null) { |
98 if (file != null) { |
91 print(","); |
99 print(","); |
92 try { |
100 try { |
93 print(" "); |
101 print(" "); |
94 long bytes = SecuritySupport.getFileSize(file); |
102 long bytes = SecuritySupport.getFileSize(file); |
134 print(s, args); |
142 print(s, args); |
135 println(); |
143 println(); |
136 } |
144 } |
137 |
145 |
138 protected final void printBytes(long bytes, String separation) { |
146 protected final void printBytes(long bytes, String separation) { |
139 print(Utils.formatBytes(bytes, separation)); |
147 print(Utils.formatBytes(bytes, separation)); |
140 } |
148 } |
141 |
149 |
142 protected final void printTimespan(Duration timespan, String separator) { |
150 protected final void printTimespan(Duration timespan, String separator) { |
143 print(Utils.formatTimespan(timespan, separator)); |
151 print(Utils.formatTimespan(timespan, separator)); |
144 } |
152 } |