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