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 java.io.InputStream;
11 import java.io.OutputStream;
13 import javax.annotation.concurrent.ThreadSafe;
15 import org.apache.commons.io.IOUtils;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 import ch.ethz.ssh2.ServerConnection;
20 import ch.ethz.ssh2.ServerSession;
23 public class IOThread extends Thread {
25 private static final Logger logger = LoggerFactory.getLogger(IOThread.class);
27 private final InputStream inputStream;
28 private final OutputStream outputStream;
29 private final ServerSession servSession;
30 private final ServerConnection servconnection;
31 private String customHeader;
34 public IOThread (InputStream is, OutputStream os, String id,ServerSession ss, ServerConnection conn){
35 this.inputStream = is;
36 this.outputStream = os;
37 this.servSession = ss;
38 this.servconnection = conn;
40 logger.trace("IOThread {} created", super.getName());
43 public IOThread (InputStream is, OutputStream os, String id,ServerSession ss, ServerConnection conn,String header){
44 this.inputStream = is;
45 this.outputStream = os;
46 this.servSession = ss;
47 this.servconnection = conn;
48 this.customHeader = header;
50 logger.trace("IOThread {} created", super.getName());
55 logger.trace("thread {} started", super.getName());
57 if (this.customHeader!=null && !this.customHeader.equals("")){
58 this.outputStream.write(this.customHeader.getBytes());
59 logger.trace("adding {} header", this.customHeader);
61 IOUtils.copy(this.inputStream, this.outputStream);
62 } catch (Exception e) {
63 logger.error("inputstream -> outputstream copy error ",e);
65 logger.trace("closing server session");
67 servconnection.close();
68 logger.trace("thread {} is closing",super.getName());