langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/RemoteExecutionControl.java
changeset 41994 e43f670394ca
parent 41941 a935ac3f5274
child 41995 1ac75bf2dc3a
equal deleted inserted replaced
41993:c8260c3ae93b 41994:e43f670394ca
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 package jdk.jshell.execution;
    25 package jdk.jshell.execution;
    26 
    26 
       
    27 import java.io.IOException;
    27 import java.io.InputStream;
    28 import java.io.InputStream;
    28 import java.io.OutputStream;
    29 import java.io.OutputStream;
    29 import java.io.PrintStream;
    30 import java.io.PrintStream;
    30 import java.lang.reflect.Method;
    31 import java.lang.reflect.Method;
    31 import java.net.Socket;
    32 import java.net.Socket;
    55      * @param args standard command-line arguments, expectation is the socket
    56      * @param args standard command-line arguments, expectation is the socket
    56      * number is the only argument
    57      * number is the only argument
    57      * @throws Exception any unexpected exception
    58      * @throws Exception any unexpected exception
    58      */
    59      */
    59     public static void main(String[] args) throws Exception {
    60     public static void main(String[] args) throws Exception {
       
    61         InputStream fd0 = System.in;
    60         String loopBack = null;
    62         String loopBack = null;
    61         Socket socket = new Socket(loopBack, Integer.parseInt(args[0]));
    63         Socket socket = new Socket(loopBack, Integer.parseInt(args[0]));
    62         InputStream inStream = socket.getInputStream();
    64         InputStream inStream = socket.getInputStream();
    63         OutputStream outStream = socket.getOutputStream();
    65         OutputStream outStream = socket.getOutputStream();
    64         Map<String, Consumer<OutputStream>> outputs = new HashMap<>();
    66         Map<String, Consumer<OutputStream>> outputs = new HashMap<>();
    65         outputs.put("out", st -> System.setOut(new PrintStream(st, true)));
    67         outputs.put("out", st -> System.setOut(new PrintStream(st, true)));
    66         outputs.put("err", st -> System.setErr(new PrintStream(st, true)));
    68         outputs.put("err", st -> System.setErr(new PrintStream(st, true)));
       
    69         outputs.put("echo", st -> {
       
    70             new Thread(() -> {
       
    71                 try {
       
    72                     int read;
       
    73 
       
    74                     while ((read = fd0.read()) != (-1)) {
       
    75                         st.write(read);
       
    76                     }
       
    77                 } catch (IOException ex) {
       
    78                     ex.printStackTrace();
       
    79                 } finally {
       
    80                     try {
       
    81                         st.close();
       
    82                     } catch (IOException ex) {
       
    83                         ex.printStackTrace();
       
    84                     }
       
    85                 }
       
    86             }).start();
       
    87         });
    67         Map<String, Consumer<InputStream>> input = new HashMap<>();
    88         Map<String, Consumer<InputStream>> input = new HashMap<>();
    68         input.put("in", st -> System.setIn(st));
    89         input.put("in", st -> System.setIn(st));
    69         forwardExecutionControlAndIO(new RemoteExecutionControl(), inStream, outStream, outputs, input);
    90         forwardExecutionControlAndIO(new RemoteExecutionControl(), inStream, outStream, outputs, input);
    70     }
    91     }
    71 
    92