Merge "Re-Enable the pax-exam execution in Eclipse"
[controller.git] / opendaylight / netconf / netconf-ssh / src / main / java / org / opendaylight / controller / netconf / ssh / threads / IOThread.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 package org.opendaylight.controller.netconf.ssh.threads;
9
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;
18
19 @ThreadSafe
20 public class IOThread extends Thread {
21
22     private static final Logger logger =  LoggerFactory.getLogger(IOThread.class);
23
24     private InputStream inputStream;
25     private OutputStream outputStream;
26     private String id;
27     private ServerSession servSession;
28     private ServerConnection servconnection;
29
30
31     public IOThread (InputStream is, OutputStream os, String id,ServerSession ss, ServerConnection conn){
32         this.inputStream = is;
33         this.outputStream = os;
34         this.servSession = ss;
35         this.servconnection = conn;
36         super.setName(id);
37         logger.trace("IOThread {} created", super.getName());
38     }
39
40     @Override
41     public void run() {
42         logger.trace("thread {} started", super.getName());
43         try {
44             IOUtils.copy(this.inputStream, this.outputStream);
45         } catch (Exception e) {
46             logger.error("inputstream -> outputstream copy error ",e);
47         }
48         logger.trace("closing server session");
49         servSession.close();
50         servconnection.close();
51         logger.trace("thread {} is closing",super.getName());
52     }
53 }