< prev index next >

src/jdk.jshell/share/classes/jdk/jshell/execution/DemultiplexInput.java

Print this page
rev 3613 : imported patch 8131023

@@ -38,19 +38,18 @@
  * @see Util#demultiplexInput(java.io.InputStream, java.io.OutputStream, java.io.OutputStream, java.io.OutputStream...)
  */
 class DemultiplexInput extends Thread {
 
     private final DataInputStream delegate;
-    private final PipeInputStream command;
     private final Map<String, OutputStream> io;
+    private final Iterable<OutputStream> closeList;
 
-    DemultiplexInput(InputStream input, PipeInputStream command,
-            Map<String, OutputStream> io) {
+    DemultiplexInput(InputStream input, Map<String, OutputStream> io, Iterable<OutputStream> closeList) {
         super("output reader");
         this.delegate = new DataInputStream(input);
-        this.command = command;
         this.io = io;
+        this.closeList = closeList;
     }
 
     @Override
     public void run() {
         try {

@@ -63,27 +62,27 @@
                 DemultiplexInput.this.delegate.readFully(name);
                 int dataLen = delegate.read();
                 byte[] data = new byte[dataLen];
                 DemultiplexInput.this.delegate.readFully(data);
                 String chan = new String(name, "UTF-8");
-                if (chan.equals("command")) {
-                    for (byte b : data) {
-                        command.write(Byte.toUnsignedInt(b));
-                    }
-                } else {
                     OutputStream out = io.get(chan);
                     if (out == null) {
                         debug("Unexpected channel name: %s", chan);
                     } else {
                         out.write(data);
                     }
                 }
-            }
         } catch (IOException ex) {
             debug(ex, "Failed reading output");
         } finally {
-            command.close();
+            for (OutputStream out : closeList) {
+                try {
+                    out.close();
+                } catch (IOException ex) {
+                    debug(ex, "Failed reading output");
+                }
+            }
         }
     }
 
     /**
      * Log debugging information. Arguments as for {@code printf}.
< prev index next >