001 package org.kuali.common.util.secure;
002
003 public class ChannelUtils {
004
005 public static String getLocation(String username, String hostname, RemoteFile file) {
006 return getLocation(username, hostname) + ":" + file.getAbsolutePath();
007 }
008
009 public static String getLocation(String username, String hostname) {
010 return (username == null) ? hostname : username + "@" + hostname;
011 }
012
013 public static Result getExecutionResult(int exitValue, long start, String command, String stdin, String stdout, String stderr, String encoding) {
014 long stop = System.currentTimeMillis();
015 long elapsed = stop - start;
016 Result result = new Result();
017 result.setEncoding(encoding);
018 result.setCommand(command);
019 result.setElapsed(elapsed);
020 result.setStart(start);
021 result.setStop(stop);
022 result.setExitValue(exitValue);
023 result.setStdin(stdin);
024 result.setStdout(stdout);
025 result.setStderr(stderr);
026 return result;
027 }
028
029 public static void closeQuietly(SecureChannel channel) {
030 if (channel != null) {
031 channel.close();
032 }
033 }
034
035 }