MCPcopy Create free account
hub / github.com/anons-org/opencar / ShellUtil

Class ShellUtil

src/main/java/com/far/vms/opencar/ui/ShellUtil.java:17–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15 * @data 2022/11/29
16 */
17public class ShellUtil {
18
19
20 public static class RunShellThread implements Runnable {
21
22 private InputStream inputStream;
23
24 private Function<String, Integer> caller;
25
26 public Function<String, Integer> getCaller() {
27 return caller;
28 }
29
30 public RunShellThread setCaller(Function<String, Integer> caller) {
31 this.caller = caller;
32 return this;
33 }
34
35 public InputStream getInputStream() {
36 return inputStream;
37 }
38
39 public RunShellThread setInputStream(InputStream inputStream) {
40 this.inputStream = inputStream;
41 return this;
42 }
43
44 @Override
45 public void run() {
46
47 InputStreamReader inputStreamReader = null;
48 BufferedReader br = null;
49 try {
50 inputStreamReader = new InputStreamReader(inputStream);
51 br = new BufferedReader(inputStreamReader);
52 // 打印信息
53 String line = null;
54 while ((line = br.readLine()) != null) {
55 caller.apply(line);
56 }
57 } catch (IOException ioe) {
58 caller.apply(ioe.getMessage());
59 ioe.printStackTrace();
60 } finally {
61 try {
62 br.close();
63 inputStreamReader.close();
64 } catch (IOException e) {
65 e.printStackTrace();
66 }
67 }
68 }
69 }
70
71
72 /**
73 * @param shellProgPath
74 * @param args

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected