Bug 1586: Do not use JaxRS 2.0 unnecessarily
[controller.git] / opendaylight / netconf / netconf-netty-util / src / main / java / org / opendaylight / controller / netconf / nettyutil / handler / ssh / client / SshSession.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.nettyutil.handler.ssh.client;
10
11 import ch.ethz.ssh2.Session;
12 import ch.ethz.ssh2.StreamGobbler;
13
14 import ch.ethz.ssh2.channel.Channel;
15 import java.io.Closeable;
16 import java.io.IOException;
17 import java.io.InputStream;
18 import java.io.OutputStream;
19
20 /**
21  * Wrapper class for proprietary SSH sessions implementations
22  */
23 class SshSession implements Closeable {
24     private final Session session;
25
26     public SshSession(Session session) {
27         this.session = session;
28     }
29
30
31     public void startSubSystem(String name) throws IOException {
32         session.startSubSystem(name);
33     }
34
35     public InputStream getStdout() {
36         return new StreamGobbler(session.getStdout());
37     }
38
39     public InputStream getStderr() {
40         return session.getStderr();
41     }
42
43     public OutputStream getStdin() {
44         return session.getStdin();
45     }
46
47     @Override
48     public void close() {
49         if (session.getState() == Channel.STATE_OPEN || session.getState() == Channel.STATE_OPENING) {
50             session.close();
51         }
52     }
53 }