From db1723c5fbeae563339e322d9794971803d183b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandar=20Pejovi=C4=87?= Date: Thu, 25 May 2023 12:43:57 +0200 Subject: [PATCH] Use java.io for reading cgroup files --- .../jdk/internal/platform/CgroupUtil.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/java.base/linux/classes/jdk/internal/platform/CgroupUtil.java b/src/java.base/linux/classes/jdk/internal/platform/CgroupUtil.java index dbe8a85b2b2..23d0cd0ccb6 100644 --- a/src/java.base/linux/classes/jdk/internal/platform/CgroupUtil.java +++ b/src/java.base/linux/classes/jdk/internal/platform/CgroupUtil.java @@ -26,14 +26,17 @@ package jdk.internal.platform; import java.io.BufferedReader; +import java.io.FileReader; import java.io.IOException; import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; @@ -64,7 +67,7 @@ static void unwrapIOExceptionAndRethrow(PrivilegedActionException pae) throws IO static String readStringValue(CgroupSubsystemController controller, String param) throws IOException { PrivilegedExceptionAction pea = () -> - Files.newBufferedReader(Paths.get(controller.path(), param)); + new BufferedReader(new FileReader(Paths.get(controller.path(), param).toString(), StandardCharsets.UTF_8)); try (@SuppressWarnings("removal") BufferedReader bufferedReader = AccessController.doPrivileged(pea)) { String line = bufferedReader.readLine(); @@ -72,21 +75,26 @@ static String readStringValue(CgroupSubsystemController controller, String param } catch (PrivilegedActionException e) { unwrapIOExceptionAndRethrow(e); throw new InternalError(e.getCause()); - } catch (UncheckedIOException e) { - throw e.getCause(); } } @SuppressWarnings("removal") public static List readAllLinesPrivileged(Path path) throws IOException { try { - PrivilegedExceptionAction> pea = () -> Files.readAllLines(path); + PrivilegedExceptionAction> pea = () -> { + try (BufferedReader bufferedReader = new BufferedReader(new FileReader(path.toString(), StandardCharsets.UTF_8))) { + String line; + List lines = new ArrayList<>(); + while ((line = bufferedReader.readLine()) != null) { + lines.add(line); + } + return lines; + } + }; return AccessController.doPrivileged(pea); } catch (PrivilegedActionException e) { unwrapIOExceptionAndRethrow(e); throw new InternalError(e.getCause()); - } catch (UncheckedIOException e) { - throw e.getCause(); } } }