1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.secure;
17
18 public class ChannelUtils {
19
20 public static String getLocation(String username, String hostname, RemoteFile file) {
21 return getLocation(username, hostname) + ":" + file.getAbsolutePath();
22 }
23
24 public static String getLocation(String username, String hostname) {
25 return (username == null) ? hostname : username + "@" + hostname;
26 }
27
28 public static Result getExecutionResult(int exitValue, long start, String command, String stdin, String stdout, String stderr, String encoding) {
29 long stop = System.currentTimeMillis();
30 long elapsed = stop - start;
31 Result result = new Result();
32 result.setEncoding(encoding);
33 result.setCommand(command);
34 result.setElapsed(elapsed);
35 result.setStart(start);
36 result.setStop(stop);
37 result.setExitValue(exitValue);
38 result.setStdin(stdin);
39 result.setStdout(stdout);
40 result.setStderr(stderr);
41 return result;
42 }
43
44 public static void closeQuietly(SecureChannel channel) {
45 if (channel != null) {
46 channel.close();
47 }
48 }
49
50 }