< prev index next >

src/jdk.jcmd/share/classes/sun/tools/jstack/JStack.java

Print this page
rev 55749 : 8227868: jinfo and jstack can fail converting UTF8 output to strings
Reviewed-by:

@@ -27,13 +27,13 @@
 
 import java.io.InputStream;
 import java.util.Collection;
 
 import com.sun.tools.attach.VirtualMachine;
-import com.sun.tools.attach.VirtualMachineDescriptor;
 import sun.tools.attach.HotSpotVirtualMachine;
 import sun.tools.common.ProcessArgumentMatcher;
+import sun.tools.common.PrintStreamPrinter;
 
 /*
  * This class is the main class for the JStack utility. It parses its arguments
  * and decides if the command should be executed by the SA JStack tool or by
  * obtained the thread dump from a target process using the VM attach mechanism

@@ -126,22 +126,12 @@
         }
 
         // Cast to HotSpotVirtualMachine as this is implementation specific
         // method.
         InputStream in = ((HotSpotVirtualMachine)vm).remoteDataDump((Object[])args);
-
         // read to EOF and just print output
-        byte b[] = new byte[256];
-        int n;
-        do {
-            n = in.read(b);
-            if (n > 0) {
-                String s = new String(b, 0, n, "UTF-8");
-                System.out.print(s);
-            }
-        } while (n > 0);
-        in.close();
+        PrintStreamPrinter.drainUTF8(in, System.out);
         vm.detach();
     }
 
     private static void checkForUnsupportedOptions(String[] args) {
         // Check arguments for -F, -m, and non-numeric value
< prev index next >