package hudson.remoting;

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
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);
        main(System.in,os);
        System.exit(0);
    }

    public static void main(InputStream is, OutputStream os) throws IOException, InterruptedException {
        ExecutorService executor = Executors.newCachedThreadPool();
        Channel channel = new Channel("channel", executor, is, os);
        System.err.println("channel started");
        channel.join();
        System.err.println("channel stopped");
    }
}

@@ -19,16 +19,54 @@
 oting;%0A%0A
+import hudson.remoting.Channel.Mode;%0A%0A
 import j
@@ -78,32 +78,32 @@
 o.OutputStream;%0A
-
 import java.io.I
@@ -508,32 +508,302 @@
 ows Exception %7B%0A
+        Mode m = Mode.BINARY;%0A%0A        for (String arg : args) %7B%0A            if(arg.equals(%22-text%22)) %7B%0A                m = Mode.TEXT;%0A                continue;%0A            %7D%0A            System.err.println(%22Invalid option: %22+arg);%0A            System.exit(-1);%0A        %7D%0A%0A
         // this 
@@ -1000,16 +1000,18 @@
 em.in,os
+,m
 );%0A     
@@ -1095,16 +1095,27 @@
 tream os
+, Mode mode
 ) throws
@@ -1215,24 +1215,24 @@
 readPool();%0A
-
         Chan
@@ -1277,16 +1277,22 @@
 xecutor,
+ mode,
  is, os)

support the -text option for slaves over binary-unsafe channel.