2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.netconf.nettyutil.handler.ssh.client;
11 import ch.ethz.ssh2.Session;
12 import ch.ethz.ssh2.StreamGobbler;
14 import java.io.Closeable;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.io.OutputStream;
20 * Wrapper class for proprietary SSH sessions implementations
22 public class SshSession implements Closeable {
23 private final Session session;
25 public SshSession(Session session) {
26 this.session = session;
29 public void execCommand(String cmd) throws IOException {
30 session.execCommand(cmd);
33 public void execCommand(String cmd, String charsetName) throws IOException {
34 session.execCommand(cmd, charsetName);
37 public void startShell() throws IOException {
41 public void startSubSystem(String name) throws IOException {
42 session.startSubSystem(name);
45 public int getState() {
46 return session.getState();
49 public InputStream getStdout() {
50 return new StreamGobbler(session.getStdout());
53 public InputStream getStderr() {
54 return session.getStderr();
57 public OutputStream getStdin() {
58 return session.getStdin();
61 public int waitUntilDataAvailable(long timeout) throws IOException {
62 return session.waitUntilDataAvailable(timeout);
65 public int waitForCondition(int conditionSet, long timeout) {
66 return session.waitForCondition(conditionSet, timeout);
69 public Integer getExitStatus() {
70 return session.getExitStatus();
73 public String getExitSignal() {
74 return session.getExitSignal();