@@ -41,6 +41,10 @@ public final class SystemUtil {
41
41
42
42
private final static String SPLIT_REGEX = "((\" .+?\" |[^'\\ s]|'.+?')+)\\ s*" ;
43
43
44
+ private SystemUtil () {
45
+ // Empty constructor.
46
+ }
47
+
44
48
/**
45
49
* Gets seed as long value of current time in milliseconds.
46
50
*
@@ -59,10 +63,6 @@ public static int getTimeBasedIntSeed() {
59
63
return (int ) System .currentTimeMillis ();
60
64
}
61
65
62
- private SystemUtil () {
63
- // Empty constructor.
64
- }
65
-
66
66
/**
67
67
* Should be used in relative constructs (for example to check how many milliseconds have passed).
68
68
*
@@ -75,6 +75,15 @@ public static long getRelativeTimeMillis() {
75
75
return System .currentTimeMillis ();
76
76
}
77
77
78
+ /**
79
+ * Gets current time in milliseconds since the epoch (January 1, 1970, 00:00:00 GMT).
80
+ *
81
+ * @return current time in milliseconds.
82
+ */
83
+ public static long currentTimeMillis () {
84
+ return System .currentTimeMillis ();
85
+ }
86
+
78
87
/**
79
88
* Gets free available memory for JDK.
80
89
*
@@ -88,6 +97,7 @@ public static long getFreeMemory() {
88
97
* Gets either java property or environment variable with given name.
89
98
*
90
99
* @param name the name of either java property or environment variable.
100
+ *
91
101
* @return property or variable value or null if there is no such.
92
102
*/
93
103
public static String getPropertyOrEnvironmentVariable (String name ) {
@@ -99,88 +109,96 @@ public static String getPropertyOrEnvironmentVariable(String name) {
99
109
}
100
110
101
111
/**
102
- * Executes the specified command and arguments in a separate process with the specified environment and working directory.
112
+ * Executes the specified command and arguments in a separate process with the specified environment and working
113
+ * directory.
103
114
* This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
104
115
* but at the very least the command must be a non-empty and non-null.
105
116
* The subprocess inherits the environment settings of the current process.
106
- * A minimal set of system dependent environment variables may be required to start a process on some operating systems.
117
+ * A minimal set of system dependent environment variables may be required to start a process on some operating
118
+ * systems.
107
119
* The working directory of the new subprocess is the current working directory of the current process.
108
120
*
109
- * @param exec a specified system command.
121
+ * @param exec a specified system command.
110
122
* @param params a parameters for the specifed system command.
111
123
*
112
124
* @return true if subprocess was successfully executed, false otherwise.
113
125
*
114
- * @throws IOException if any I/O error occurs.
126
+ * @throws IOException if any I/O error occurs.
115
127
* @throws InterruptedException if process was interrupted.
116
128
*/
117
129
public static boolean runProcessAndWait (String exec , String params ) throws IOException , InterruptedException {
118
130
return runProcessAndWait (exec , params , null );
119
131
}
120
132
121
133
/**
122
- * Executes the specified command and arguments in a separate process with the specified environment and working directory.
134
+ * Executes the specified command and arguments in a separate process with the specified environment and working
135
+ * directory.
123
136
* This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
124
137
* but at the very least the command must be a non-empty and non-null.
125
138
* The subprocess inherits the environment settings of the current process.
126
- * A minimal set of system dependent environment variables may be required to start a process on some operating systems.
139
+ * A minimal set of system dependent environment variables may be required to start a process on some operating
140
+ * systems.
127
141
* The working directory of the new subprocess is specified by workingDirPath.
128
142
* If dir is null, the subprocess inherits the current working directory of the current process.
129
143
*
130
- * @param exec a specified system command.
131
- * @param params a parameters for the specifed system command.
144
+ * @param exec a specified system command.
145
+ * @param params a parameters for the specifed system command.
132
146
* @param workingDirPath working dir for subprocess.
133
147
*
134
148
* @return true if subprocess was successfully executed, false otherwise.
135
149
*
136
- * @throws IOException if any I/O error occurs.
150
+ * @throws IOException if any I/O error occurs.
137
151
* @throws InterruptedException if process was interrupted.
138
152
*/
139
153
public static boolean runProcessAndWait (String exec , String params ,
140
- String workingDirPath ) throws IOException , InterruptedException {
154
+ String workingDirPath ) throws IOException , InterruptedException {
141
155
return runProcessAndGetExitCode (exec , params , workingDirPath ) == 0 ;
142
156
}
143
157
144
158
/**
145
- * Executes the specified command and arguments in a separate process with the specified environment and working directory.
159
+ * Executes the specified command and arguments in a separate process with the specified environment and working
160
+ * directory.
146
161
* This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
147
162
* but at the very least the command must be a non-empty and non-null.
148
163
* The subprocess inherits the environment settings of the current process.
149
- * A minimal set of system dependent environment variables may be required to start a process on some operating systems.
164
+ * A minimal set of system dependent environment variables may be required to start a process on some operating
165
+ * systems.
150
166
* The working directory of the new subprocess is the current working directory of the current process.
151
167
*
152
- * @param exec a specified system command.
168
+ * @param exec a specified system command.
153
169
* @param params a parameters for the specifed system command.
154
170
*
155
171
* @return exit code.
156
172
*
157
- * @throws IOException if any I/O error occurs.
173
+ * @throws IOException if any I/O error occurs.
158
174
* @throws InterruptedException if process was interrupted.
159
175
*/
160
176
public static int runProcessAndGetExitCode (String exec , String params ) throws IOException , InterruptedException {
161
177
return runProcessAndGetExitCode (exec , params , null );
162
178
}
163
179
164
180
/**
165
- * Executes the specified command and arguments in a separate process with the specified environment and working directory.
181
+ * Executes the specified command and arguments in a separate process with the specified environment and working
182
+ * directory.
166
183
* This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
167
184
* but at the very least the command must be a non-empty and non-null.
168
185
* The subprocess inherits the environment settings of the current process.
169
- * A minimal set of system dependent environment variables may be required to start a process on some operating systems.
186
+ * A minimal set of system dependent environment variables may be required to start a process on some operating
187
+ * systems.
170
188
* The working directory of the new subprocess is specified by workingDirPath.
171
189
* If dir is null, the subprocess inherits the current working directory of the current process.
172
190
*
173
- * @param exec a specified system command.
174
- * @param params a parameters for the specifed system command.
191
+ * @param exec a specified system command.
192
+ * @param params a parameters for the specifed system command.
175
193
* @param workingDirPath working dir for subprocess.
176
194
*
177
195
* @return exit code.
178
196
*
179
- * @throws IOException if any I/O error occurs.
197
+ * @throws IOException if any I/O error occurs.
180
198
* @throws InterruptedException if process was interrupted.
181
199
*/
182
200
public static int runProcessAndGetExitCode (String exec , String params ,
183
- String workingDirPath ) throws IOException , InterruptedException {
201
+ String workingDirPath ) throws IOException , InterruptedException {
184
202
Process p = runProcess (exec , params , workingDirPath );
185
203
System .out .println (getProcessOutput (p ));
186
204
return p .waitFor ();
@@ -192,12 +210,13 @@ public static int runProcessAndGetExitCode(String exec, String params,
192
210
* This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
193
211
* but at the very least the command must be a non-empty and non-null.
194
212
* The subprocess inherits the environment settings of the current process.
195
- * A minimal set of system dependent environment variables may be required to start a process on some operating systems.
213
+ * A minimal set of system dependent environment variables may be required to start a process on some operating
214
+ * systems.
196
215
* The working directory of the new subprocess is specified by workingDirPath.
197
216
* If dir is null, the subprocess inherits the current working directory of the current process.
198
217
*
199
218
* @param command a specified system command.
200
- * @param params a parameters for the specifed system command.
219
+ * @param params a parameters for the specifed system command.
201
220
*
202
221
* @return subprocess output result.
203
222
*
@@ -213,12 +232,13 @@ public static String runProcessAndGetOutput(String command, String params) throw
213
232
* This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
214
233
* but at the very least the command must be a non-empty and non-null.
215
234
* The subprocess inherits the environment settings of the current process.
216
- * A minimal set of system dependent environment variables may be required to start a process on some operating systems.
235
+ * A minimal set of system dependent environment variables may be required to start a process on some operating
236
+ * systems.
217
237
* The working directory of the new subprocess is specified by workingDirPath.
218
238
* If dir is null, the subprocess inherits the current working directory of the current process.
219
239
*
220
240
* @param execPath a specified system command.
221
- * @param params a parameters for the specifed system command.
241
+ * @param params a parameters for the specifed system command.
222
242
*
223
243
* @return subprocess errors as {@code StringBuilder}.
224
244
*
@@ -234,16 +254,17 @@ public static StringBuilder runProcessAndCollectErrors(String execPath, String p
234
254
* This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
235
255
* but at the very least the command must be a non-empty and non-null.
236
256
* The subprocess inherits the environment settings of the current process.
237
- * A minimal set of system dependent environment variables may be required to start a process on some operating systems.
257
+ * A minimal set of system dependent environment variables may be required to start a process on some operating
258
+ * systems.
238
259
* The working directory of the new subprocess is specified by workingDirPath.
239
260
* If dir is null, the subprocess inherits the current working directory of the current process.
240
261
*
241
262
* @param command a specified system command.
242
- * @param params a parameters for the specifed system command.
263
+ * @param params a parameters for the specifed system command.
243
264
*
244
265
* @return process info instance.
245
266
*
246
- * @throws IOException if any I/O error occurs.
267
+ * @throws IOException if any I/O error occurs.
247
268
* @throws InterruptedException if process was interrupted.
248
269
*/
249
270
public static ProcessInfo runProcessAndGetProcessInfo (String command , String params ) throws IOException ,
0 commit comments