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
8 package org.opendaylight.controller.netconf.ssh.threads;
10 import ch.ethz.ssh2.ServerConnection;
11 import ch.ethz.ssh2.ServerSession;
12 import java.io.InputStream;
13 import java.io.OutputStream;
14 import javax.annotation.concurrent.ThreadSafe;
15 import org.apache.commons.io.IOUtils;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 public class IOThread extends Thread {
22 private static final Logger logger = LoggerFactory.getLogger(IOThread.class);
24 private InputStream inputStream;
25 private OutputStream outputStream;
27 private ServerSession servSession;
28 private ServerConnection servconnection;
29 private String customHeader;
32 public IOThread (InputStream is, OutputStream os, String id,ServerSession ss, ServerConnection conn){
33 this.inputStream = is;
34 this.outputStream = os;
35 this.servSession = ss;
36 this.servconnection = conn;
38 logger.trace("IOThread {} created", super.getName());
40 public IOThread (InputStream is, OutputStream os, String id,ServerSession ss, ServerConnection conn,String header){
41 this.inputStream = is;
42 this.outputStream = os;
43 this.servSession = ss;
44 this.servconnection = conn;
45 this.customHeader = header;
47 logger.trace("IOThread {} created", super.getName());
52 logger.trace("thread {} started", super.getName());
54 if (this.customHeader!=null && !this.customHeader.equals("")){
55 this.outputStream.write(this.customHeader.getBytes());
56 logger.trace("adding {} header", this.customHeader);
58 IOUtils.copy(this.inputStream, this.outputStream);
59 } catch (Exception e) {
60 logger.error("inputstream -> outputstream copy error ",e);
62 logger.trace("closing server session");
64 servconnection.close();
65 logger.trace("thread {} is closing",super.getName());