@@ -41,6 +41,10 @@ public final class SystemUtil {
4141
4242 private final static String SPLIT_REGEX = "((\" .+?\" |[^'\\ s]|'.+?')+)\\ s*" ;
4343
44+ private SystemUtil () {
45+ // Empty constructor.
46+ }
47+
4448 /**
4549 * Gets seed as long value of current time in milliseconds.
4650 *
@@ -59,10 +63,6 @@ public static int getTimeBasedIntSeed() {
5963 return (int ) System .currentTimeMillis ();
6064 }
6165
62- private SystemUtil () {
63- // Empty constructor.
64- }
65-
6666 /**
6767 * Should be used in relative constructs (for example to check how many milliseconds have passed).
6868 *
@@ -75,6 +75,15 @@ public static long getRelativeTimeMillis() {
7575 return System .currentTimeMillis ();
7676 }
7777
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+
7887 /**
7988 * Gets free available memory for JDK.
8089 *
@@ -88,6 +97,7 @@ public static long getFreeMemory() {
8897 * Gets either java property or environment variable with given name.
8998 *
9099 * @param name the name of either java property or environment variable.
100+ *
91101 * @return property or variable value or null if there is no such.
92102 */
93103 public static String getPropertyOrEnvironmentVariable (String name ) {
@@ -99,88 +109,96 @@ public static String getPropertyOrEnvironmentVariable(String name) {
99109 }
100110
101111 /**
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.
103114 * This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
104115 * but at the very least the command must be a non-empty and non-null.
105116 * 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.
107119 * The working directory of the new subprocess is the current working directory of the current process.
108120 *
109- * @param exec a specified system command.
121+ * @param exec a specified system command.
110122 * @param params a parameters for the specifed system command.
111123 *
112124 * @return true if subprocess was successfully executed, false otherwise.
113125 *
114- * @throws IOException if any I/O error occurs.
126+ * @throws IOException if any I/O error occurs.
115127 * @throws InterruptedException if process was interrupted.
116128 */
117129 public static boolean runProcessAndWait (String exec , String params ) throws IOException , InterruptedException {
118130 return runProcessAndWait (exec , params , null );
119131 }
120132
121133 /**
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.
123136 * This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
124137 * but at the very least the command must be a non-empty and non-null.
125138 * 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.
127141 * The working directory of the new subprocess is specified by workingDirPath.
128142 * If dir is null, the subprocess inherits the current working directory of the current process.
129143 *
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.
132146 * @param workingDirPath working dir for subprocess.
133147 *
134148 * @return true if subprocess was successfully executed, false otherwise.
135149 *
136- * @throws IOException if any I/O error occurs.
150+ * @throws IOException if any I/O error occurs.
137151 * @throws InterruptedException if process was interrupted.
138152 */
139153 public static boolean runProcessAndWait (String exec , String params ,
140- String workingDirPath ) throws IOException , InterruptedException {
154+ String workingDirPath ) throws IOException , InterruptedException {
141155 return runProcessAndGetExitCode (exec , params , workingDirPath ) == 0 ;
142156 }
143157
144158 /**
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.
146161 * This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
147162 * but at the very least the command must be a non-empty and non-null.
148163 * 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.
150166 * The working directory of the new subprocess is the current working directory of the current process.
151167 *
152- * @param exec a specified system command.
168+ * @param exec a specified system command.
153169 * @param params a parameters for the specifed system command.
154170 *
155171 * @return exit code.
156172 *
157- * @throws IOException if any I/O error occurs.
173+ * @throws IOException if any I/O error occurs.
158174 * @throws InterruptedException if process was interrupted.
159175 */
160176 public static int runProcessAndGetExitCode (String exec , String params ) throws IOException , InterruptedException {
161177 return runProcessAndGetExitCode (exec , params , null );
162178 }
163179
164180 /**
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.
166183 * This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
167184 * but at the very least the command must be a non-empty and non-null.
168185 * 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.
170188 * The working directory of the new subprocess is specified by workingDirPath.
171189 * If dir is null, the subprocess inherits the current working directory of the current process.
172190 *
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.
175193 * @param workingDirPath working dir for subprocess.
176194 *
177195 * @return exit code.
178196 *
179- * @throws IOException if any I/O error occurs.
197+ * @throws IOException if any I/O error occurs.
180198 * @throws InterruptedException if process was interrupted.
181199 */
182200 public static int runProcessAndGetExitCode (String exec , String params ,
183- String workingDirPath ) throws IOException , InterruptedException {
201+ String workingDirPath ) throws IOException , InterruptedException {
184202 Process p = runProcess (exec , params , workingDirPath );
185203 System .out .println (getProcessOutput (p ));
186204 return p .waitFor ();
@@ -192,12 +210,13 @@ public static int runProcessAndGetExitCode(String exec, String params,
192210 * This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
193211 * but at the very least the command must be a non-empty and non-null.
194212 * 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.
196215 * The working directory of the new subprocess is specified by workingDirPath.
197216 * If dir is null, the subprocess inherits the current working directory of the current process.
198217 *
199218 * @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.
201220 *
202221 * @return subprocess output result.
203222 *
@@ -213,12 +232,13 @@ public static String runProcessAndGetOutput(String command, String params) throw
213232 * This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
214233 * but at the very least the command must be a non-empty and non-null.
215234 * 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.
217237 * The working directory of the new subprocess is specified by workingDirPath.
218238 * If dir is null, the subprocess inherits the current working directory of the current process.
219239 *
220240 * @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.
222242 *
223243 * @return subprocess errors as {@code StringBuilder}.
224244 *
@@ -234,16 +254,17 @@ public static StringBuilder runProcessAndCollectErrors(String execPath, String p
234254 * This method checks that exec is a valid operating system command. Which commands are valid is system-dependent,
235255 * but at the very least the command must be a non-empty and non-null.
236256 * 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.
238259 * The working directory of the new subprocess is specified by workingDirPath.
239260 * If dir is null, the subprocess inherits the current working directory of the current process.
240261 *
241262 * @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.
243264 *
244265 * @return process info instance.
245266 *
246- * @throws IOException if any I/O error occurs.
267+ * @throws IOException if any I/O error occurs.
247268 * @throws InterruptedException if process was interrupted.
248269 */
249270 public static ProcessInfo runProcessAndGetProcessInfo (String command , String params ) throws IOException ,
0 commit comments