|
2 | 2 |
|
3 | 3 | import com.mycmd.Command; |
4 | 4 | import com.mycmd.ShellContext; |
5 | | -<<<<<<< HEAD |
6 | | - |
7 | | -import java.io.IOException; |
8 | | - |
9 | | -/** |
10 | | - * Delays execution for a specified time period. |
11 | | - * |
12 | | - * Usage: |
13 | | - * - timeout /T 10 : Wait 10 seconds |
14 | | - * - timeout 5 : Wait 5 seconds |
15 | | - */ |
16 | | -public class TimeoutCommand implements Command { |
17 | | - |
18 | | - @Override |
19 | | - public void execute(String[] args, ShellContext context) throws IOException { |
20 | | - if (args.length == 0) { |
21 | | - System.out.println("TIMEOUT [/T] timeout [/NOBREAK]"); |
22 | | - System.out.println("\nDescription:"); |
23 | | - System.out.println(" This utility accepts a timeout parameter to wait for the specified"); |
24 | | - System.out.println(" time period (in seconds) or until any key is pressed. It also accepts"); |
25 | | - System.out.println(" a parameter to ignore the key press."); |
26 | | - System.out.println("\nParameter List:"); |
27 | | - System.out.println(" /T timeout Specifies the number of seconds to wait."); |
28 | | - System.out.println(" Valid range is -1 to 99999 seconds."); |
29 | | - System.out.println(" /NOBREAK Ignore key presses and wait specified time."); |
30 | | - return; |
31 | | - } |
32 | | - |
33 | | - int seconds = 0; |
34 | | - boolean noBreak = false; |
35 | | - |
36 | | - for (int i = 0; i < args.length; i++) { |
37 | | - String arg = args[i].toUpperCase(); |
38 | | - |
39 | | - if (arg.equals("/T") && i + 1 < args.length) { |
40 | | - try { |
41 | | - seconds = Integer.parseInt(args[++i]); |
42 | | - } catch (NumberFormatException e) { |
43 | | - System.out.println("ERROR: Invalid argument/option - '" + args[i] + "'."); |
44 | | - return; |
45 | | - } |
46 | | - } else if (arg.equals("/NOBREAK")) { |
47 | | - noBreak = true; |
48 | | - } else { |
49 | | - try { |
50 | | - seconds = Integer.parseInt(arg); |
51 | | - } catch (NumberFormatException e) { |
52 | | - System.out.println("ERROR: Invalid argument/option - '" + arg + "'."); |
53 | | - return; |
54 | | - } |
55 | | - } |
56 | | - } |
57 | | - |
58 | | - if (seconds < 0) { |
59 | | - System.out.println("Waiting forever - press any key to continue..."); |
60 | | - try { |
61 | | - System.in.read(); |
62 | | - } catch (IOException e) { |
63 | | - // Ignore |
64 | | - } |
65 | | - } else { |
66 | | - System.out.println("Waiting for " + seconds + " seconds, press a key to continue ..."); |
67 | | - |
68 | | - try { |
69 | | - long startTime = System.currentTimeMillis(); |
70 | | - long endTime = startTime + (seconds * 1000L); |
71 | | - |
72 | | - while (System.currentTimeMillis() < endTime) { |
73 | | - if (!noBreak && System.in.available() > 0) { |
74 | | - System.in.read(); |
75 | | - break; |
76 | | - } |
77 | | - Thread.sleep(100); |
78 | | - } |
79 | | - } catch (InterruptedException | IOException e) { |
80 | | - System.out.println("Timeout interrupted."); |
81 | | - } |
82 | | - } |
83 | | - } |
84 | | - |
85 | | - @Override |
86 | | - public String description() { |
87 | | - return "Delays execution for a specified time period."; |
88 | | - } |
89 | | - |
90 | | - @Override |
91 | | - public String usage() { |
92 | | - return "timeout [/T] seconds [/NOBREAK]"; |
93 | | -======= |
94 | 5 | import java.io.IOException; |
95 | 6 | import java.util.concurrent.atomic.AtomicBoolean; |
96 | 7 |
|
@@ -273,6 +184,5 @@ public String usage() { |
273 | 184 | + "timeout /t <seconds>\n" |
274 | 185 | + "timeout /t <seconds> /nobreak\n" |
275 | 186 | + "timeout /t -1"; |
276 | | ->>>>>>> upstream/main |
277 | 187 | } |
278 | 188 | } |
0 commit comments