// Path: src/main/java/org/zeroturnaround/exec/MDCRunnableAdapter.java
// public class MDCRunnableAdapter implements Runnable {
// 
//   private final Runnable target;
// 
//   private final Map contextMap;
// 
//   public MDCRunnableAdapter(Runnable target, Map contextMap) {
//     this.target = target;
//     this.contextMap = contextMap;
//   }
// 
//   public void run() {
//     MDC.setContextMap(contextMap);
//     try {
//       target.run();
//     }
//     finally {
//       MDC.clear();
//     }
//   }
// 
// }


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.zeroturnaround.exec.MDCRunnableAdapter;
   * @param os the output stream to copy into
   * @return the stream pumper thread
   */
  protected Thread createSystemInPump(InputStream is, OutputStream os) {
    inputStreamPumper = new InputStreamPumper(is, os);
    return newThread(inputStreamPumper);
  }

  /**
   * Override this to customize how the background task is created.
   *
   * @param task the task to be run in the background
   * @return the thread of the task
   */
  protected Thread newThread(Runnable task) {
    Thread result = new Thread(wrapTask(task));
    result.setDaemon(true);
    return result;
  }

  /**
   * Override this to customize how the background task is created.
   *
   * @param task the task to be run in the background
   * @return the runnable of the wrapped task
   */
  protected Runnable wrapTask(Runnable task) {
    // Preserve the MDC context of the caller thread.
    Map contextMap = MDC.getCopyOfContextMap();
    if (contextMap != null) {
// Path: src/main/java/org/zeroturnaround/exec/MDCRunnableAdapter.java
// public class MDCRunnableAdapter implements Runnable {
// 
//   private final Runnable target;
// 
//   private final Map contextMap;
// 
//   public MDCRunnableAdapter(Runnable target, Map contextMap) {
//     this.target = target;
//     this.contextMap = contextMap;
//   }
// 
//   public void run() {
//     MDC.setContextMap(contextMap);
//     try {
//       target.run();
//     }
//     finally {
//       MDC.clear();
//     }
//   }
// 
// }


// Path: src/main/java/org/zeroturnaround/exec/stream/PumpStreamHandler.java
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.zeroturnaround.exec.MDCRunnableAdapter;

   * @param os the output stream to copy into
   * @return the stream pumper thread
   */
  protected Thread createSystemInPump(InputStream is, OutputStream os) {
    inputStreamPumper = new InputStreamPumper(is, os);
    return newThread(inputStreamPumper);
  }

  /**
   * Override this to customize how the background task is created.
   *
   * @param task the task to be run in the background
   * @return the thread of the task
   */
  protected Thread newThread(Runnable task) {
    Thread result = new Thread(wrapTask(task));
    result.setDaemon(true);
    return result;
  }

  /**
   * Override this to customize how the background task is created.
   *
   * @param task the task to be run in the background
   * @return the runnable of the wrapped task
   */
  protected Runnable wrapTask(Runnable task) {
    // Preserve the MDC context of the caller thread.
    Map contextMap = MDC.getCopyOfContextMap();
    if (contextMap != null) {
      return new MDCRunnableAdapter(task, contextMap);