Skip to content

Commit 527c385

Browse files
committed
Use java.io for reading cgroup files
1 parent 6596919 commit 527c385

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/java.base/linux/classes/jdk/internal/platform/CgroupUtil.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@
2626
package jdk.internal.platform;
2727

2828
import java.io.BufferedReader;
29+
import java.io.FileReader;
2930
import java.io.IOException;
3031
import java.io.UncheckedIOException;
32+
import java.nio.charset.StandardCharsets;
3133
import java.nio.file.Files;
3234
import java.nio.file.Path;
3335
import java.nio.file.Paths;
3436
import java.security.AccessController;
3537
import java.security.PrivilegedActionException;
3638
import java.security.PrivilegedExceptionAction;
39+
import java.util.ArrayList;
3740
import java.util.List;
3841
import java.util.stream.Stream;
3942

@@ -64,29 +67,34 @@ static void unwrapIOExceptionAndRethrow(PrivilegedActionException pae) throws IO
6467

6568
static String readStringValue(CgroupSubsystemController controller, String param) throws IOException {
6669
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));
6871
try (@SuppressWarnings("removal") BufferedReader bufferedReader =
6972
AccessController.doPrivileged(pea)) {
7073
String line = bufferedReader.readLine();
7174
return line;
7275
} catch (PrivilegedActionException e) {
7376
unwrapIOExceptionAndRethrow(e);
7477
throw new InternalError(e.getCause());
75-
} catch (UncheckedIOException e) {
76-
throw e.getCause();
7778
}
7879
}
7980

8081
@SuppressWarnings("removal")
8182
public static List<String> readAllLinesPrivileged(Path path) throws IOException {
8283
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+
};
8494
return AccessController.doPrivileged(pea);
8595
} catch (PrivilegedActionException e) {
8696
unwrapIOExceptionAndRethrow(e);
8797
throw new InternalError(e.getCause());
88-
} catch (UncheckedIOException e) {
89-
throw e.getCause();
9098
}
9199
}
92100
}

0 commit comments

Comments
 (0)