package hudson.remoting;

import java.io.OutputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Entry point for running a {@link Channel} that uses stdin/stdout.
 *
 * <p>
 * This can be used as the main class for launching a channel on
 * a separate JVM.
 *
 * @author Kohsuke Kawaguchi
 */
public class Launcher {
    public static void main(String[] args) throws Exception {
        // this will prevent programs from accidentally writing to System.out
        // and messing up the stream.
        OutputStream os = System.out;
        System.setOut(System.err);

        ExecutorService executor = Executors.newCachedThreadPool();
        Channel channel = new Channel("channel", executor, System.in, os);
        System.err.println("channel started");
        channel.join();
        System.err.println("channel stopped");
        System.exit(0);
    }
}

@@ -48,16 +48,72 @@
 Stream;%0A
+import java.io.IOException;%0Aimport java.io.InputStream;%0A
 import j
@@ -667,16 +667,178 @@
 m.err);%0A
+        main(System.in,os);%0A        System.exit(0);%0A    %7D%0A%0A    public static void main(InputStream is, OutputStream os) throws IOException, InterruptedException %7B
 %0A       
@@ -957,25 +957,18 @@
 ecutor, 
-System.in
+is
 , os);%0A 
@@ -1088,32 +1088,8 @@
 %22);%0A
-        System.exit(0);%0A
     

refactored for better reusability.