|
25 | 25 | import java.io.File;
|
26 | 26 | import java.io.FileNotFoundException;
|
27 | 27 | import java.io.FileReader;
|
| 28 | +import java.io.InputStreamReader; |
28 | 29 | import java.io.IOException;
|
29 | 30 | import java.io.Reader;
|
30 | 31 | import java.nio.CharBuffer;
|
31 | 32 | import java.util.Arrays;
|
32 |
| -import java.util.Scanner; |
33 | 33 |
|
34 | 34 | import jdk.test.lib.Asserts;
|
35 | 35 | import jdk.test.lib.JDKToolLauncher;
|
@@ -82,15 +82,22 @@ private static void testHProfFileFormat(String vmArgs, long heapSize,
|
82 | 82 | procBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
|
83 | 83 | Process largeHeapProc = procBuilder.start();
|
84 | 84 |
|
85 |
| - try (Scanner largeHeapScanner = new Scanner( |
86 |
| - largeHeapProc.getInputStream());) { |
| 85 | + try (BufferedReader r = new BufferedReader( |
| 86 | + new InputStreamReader(largeHeapProc.getInputStream()))) { |
87 | 87 | String pidstring = null;
|
88 |
| - if (!largeHeapScanner.hasNext()) { |
89 |
| - throw new RuntimeException ("Test failed: could not open largeHeapScanner."); |
| 88 | + while ((pidstring = r.readLine()) != null) { |
| 89 | + // The output might contain different VM output, skip it while searching PID line. |
| 90 | + if (pidstring.matches("PID\\[[0-9].*\\]")) { |
| 91 | + System.out.println("Found: " + pidstring); |
| 92 | + break; |
| 93 | + } else { |
| 94 | + System.out.println("Ignoring: " + pidstring); |
| 95 | + } |
90 | 96 | }
|
91 |
| - while ((pidstring = largeHeapScanner.findInLine("PID\\[[0-9].*\\]")) == null) { |
92 |
| - Thread.sleep(500); |
| 97 | + if (pidstring == null) { |
| 98 | + throw new RuntimeException("Not able to find string matching PID."); |
93 | 99 | }
|
| 100 | + |
94 | 101 | int pid = Integer.parseInt(pidstring.substring(4,
|
95 | 102 | pidstring.length() - 1));
|
96 | 103 | System.out.println("Extracted pid: " + pid);
|
|
0 commit comments