View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }