src/jdk.jcmd/share/classes/sun/tools/jcmd/JCmd.java
changeset 54566 4224f26b2e7f
parent 48543 7067fe4e054e
child 55758 bbe9c361a477
equal deleted inserted replaced
54565:3b2101f56cdd 54566:4224f26b2e7f
     1 /*
     1 /*
     2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    24  */
    24  */
    25 
    25 
    26 package sun.tools.jcmd;
    26 package sun.tools.jcmd;
    27 
    27 
    28 import java.io.InputStream;
    28 import java.io.InputStream;
       
    29 import java.io.InputStreamReader;
    29 import java.io.IOException;
    30 import java.io.IOException;
    30 import java.io.UnsupportedEncodingException;
    31 import java.io.UnsupportedEncodingException;
    31 import java.util.List;
    32 import java.util.List;
    32 import java.util.Collection;
    33 import java.util.Collection;
    33 import java.util.Collections;
    34 import java.util.Collections;
   119         String lines[] = command.split("\\n");
   120         String lines[] = command.split("\\n");
   120         for (String line : lines) {
   121         for (String line : lines) {
   121             if (line.trim().equals("stop")) {
   122             if (line.trim().equals("stop")) {
   122                 break;
   123                 break;
   123             }
   124             }
   124             try (InputStream in = hvm.executeJCmd(line);) {
   125             try (InputStream in = hvm.executeJCmd(line);
       
   126                  InputStreamReader isr = new InputStreamReader(in, "UTF-8")) {
   125                 // read to EOF and just print output
   127                 // read to EOF and just print output
   126                 byte b[] = new byte[256];
   128                 char c[] = new char[256];
   127                 int n;
   129                 int n;
   128                 boolean messagePrinted = false;
   130                 boolean messagePrinted = false;
   129                 do {
   131                 do {
   130                     n = in.read(b);
   132                     n = isr.read(c);
   131                     if (n > 0) {
   133                     if (n > 0) {
   132                         String s = new String(b, 0, n, "UTF-8");
   134                         String s = new String(c, 0, n);
   133                         System.out.print(s);
   135                         System.out.print(s);
   134                         messagePrinted = true;
   136                         messagePrinted = true;
   135                     }
   137                     }
   136                 } while (n > 0);
   138                 } while (n > 0);
   137                 if (!messagePrinted) {
   139                 if (!messagePrinted) {