|
26 | 26 | package jdk.internal.platform; |
27 | 27 |
|
28 | 28 | import java.io.BufferedReader; |
| 29 | +import java.io.FileReader; |
29 | 30 | import java.io.IOException; |
30 | 31 | import java.io.UncheckedIOException; |
| 32 | +import java.nio.charset.StandardCharsets; |
31 | 33 | import java.nio.file.Files; |
32 | 34 | import java.nio.file.Path; |
33 | 35 | import java.nio.file.Paths; |
34 | 36 | import java.security.AccessController; |
35 | 37 | import java.security.PrivilegedActionException; |
36 | 38 | import java.security.PrivilegedExceptionAction; |
| 39 | +import java.util.ArrayList; |
37 | 40 | import java.util.List; |
38 | 41 | import java.util.stream.Stream; |
39 | 42 |
|
@@ -64,29 +67,34 @@ static void unwrapIOExceptionAndRethrow(PrivilegedActionException pae) throws IO |
64 | 67 |
|
65 | 68 | static String readStringValue(CgroupSubsystemController controller, String param) throws IOException { |
66 | 69 | PrivilegedExceptionAction<BufferedReader> pea = () -> |
67 | | - Files.newBufferedReader(Paths.get(controller.path(), param)); |
| 70 | + new BufferedReader(new FileReader(Paths.get(controller.path(), param).toString(), StandardCharsets.UTF_8)); |
68 | 71 | try (@SuppressWarnings("removal") BufferedReader bufferedReader = |
69 | 72 | AccessController.doPrivileged(pea)) { |
70 | 73 | String line = bufferedReader.readLine(); |
71 | 74 | return line; |
72 | 75 | } catch (PrivilegedActionException e) { |
73 | 76 | unwrapIOExceptionAndRethrow(e); |
74 | 77 | throw new InternalError(e.getCause()); |
75 | | - } catch (UncheckedIOException e) { |
76 | | - throw e.getCause(); |
77 | 78 | } |
78 | 79 | } |
79 | 80 |
|
80 | 81 | @SuppressWarnings("removal") |
81 | 82 | public static List<String> readAllLinesPrivileged(Path path) throws IOException { |
82 | 83 | try { |
83 | | - PrivilegedExceptionAction<List<String>> pea = () -> Files.readAllLines(path); |
| 84 | + PrivilegedExceptionAction<List<String>> pea = () -> { |
| 85 | + try (BufferedReader bufferedReader = new BufferedReader(new FileReader(path.toString(), StandardCharsets.UTF_8))) { |
| 86 | + String line; |
| 87 | + List<String> lines = new ArrayList<>(); |
| 88 | + while ((line = bufferedReader.readLine()) != null) { |
| 89 | + lines.add(line); |
| 90 | + } |
| 91 | + return lines; |
| 92 | + } |
| 93 | + }; |
84 | 94 | return AccessController.doPrivileged(pea); |
85 | 95 | } catch (PrivilegedActionException e) { |
86 | 96 | unwrapIOExceptionAndRethrow(e); |
87 | 97 | throw new InternalError(e.getCause()); |
88 | | - } catch (UncheckedIOException e) { |
89 | | - throw e.getCause(); |
90 | 98 | } |
91 | 99 | } |
92 | 100 | } |
0 commit comments