Skip to content

Commit 0d29b23

Browse files
authored
[FLINK-22000][io] Set a default character set in InputStreamReader
1 parent 0270244 commit 0d29b23

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

flink-external-resources/flink-external-resource-gpu/src/main/java/org/apache/flink/externalresource/gpu/GPUDriver.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.io.File;
3737
import java.io.FileNotFoundException;
3838
import java.io.InputStreamReader;
39+
import java.nio.charset.StandardCharsets;
3940
import java.nio.file.Path;
4041
import java.nio.file.Paths;
4142
import java.util.Arrays;
@@ -133,9 +134,13 @@ private String executeDiscoveryScript(File discoveryScript, long gpuAmount, Stri
133134
final String cmd = discoveryScript.getAbsolutePath() + " " + gpuAmount + " " + args;
134135
final Process process = Runtime.getRuntime().exec(cmd);
135136
try (final BufferedReader stdoutReader =
136-
new BufferedReader(new InputStreamReader(process.getInputStream()));
137+
new BufferedReader(
138+
new InputStreamReader(
139+
process.getInputStream(), StandardCharsets.UTF_8));
137140
final BufferedReader stderrReader =
138-
new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
141+
new BufferedReader(
142+
new InputStreamReader(
143+
process.getErrorStream(), StandardCharsets.UTF_8))) {
139144
final boolean hasProcessTerminated =
140145
process.waitFor(DISCOVERY_SCRIPT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
141146
if (!hasProcessTerminated) {

flink-python/src/main/java/org/apache/flink/client/python/PythonDriver.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.BufferedReader;
3131
import java.io.File;
3232
import java.io.InputStreamReader;
33+
import java.nio.charset.StandardCharsets;
3334
import java.util.ArrayList;
3435
import java.util.List;
3536
import java.util.UUID;
@@ -101,7 +102,9 @@ public static void main(String[] args) throws Throwable {
101102
Runtime.getRuntime().addShutdownHook(shutdownHook);
102103

103104
BufferedReader in =
104-
new BufferedReader(new InputStreamReader(pythonProcess.getInputStream()));
105+
new BufferedReader(
106+
new InputStreamReader(
107+
pythonProcess.getInputStream(), StandardCharsets.UTF_8));
105108
LOG.info(
106109
"--------------------------- Python Process Started --------------------------");
107110
// print the python process output to stdout and log file

flink-runtime/src/main/java/org/apache/flink/runtime/util/Hardware.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.lang.management.OperatingSystemMXBean;
3232
import java.lang.reflect.InvocationTargetException;
3333
import java.lang.reflect.Method;
34+
import java.nio.charset.StandardCharsets;
3435
import java.util.regex.Matcher;
3536
import java.util.regex.Pattern;
3637

@@ -154,7 +155,9 @@ private static long getSizeOfPhysicalMemoryForMac() {
154155
try {
155156
Process proc = Runtime.getRuntime().exec("sysctl hw.memsize");
156157

157-
bi = new BufferedReader(new InputStreamReader(proc.getInputStream()));
158+
bi =
159+
new BufferedReader(
160+
new InputStreamReader(proc.getInputStream(), StandardCharsets.UTF_8));
158161

159162
String line;
160163
while ((line = bi.readLine()) != null) {
@@ -191,7 +194,9 @@ private static long getSizeOfPhysicalMemoryForFreeBSD() {
191194
try {
192195
Process proc = Runtime.getRuntime().exec("sysctl hw.physmem");
193196

194-
bi = new BufferedReader(new InputStreamReader(proc.getInputStream()));
197+
bi =
198+
new BufferedReader(
199+
new InputStreamReader(proc.getInputStream(), StandardCharsets.UTF_8));
195200

196201
String line;
197202
while ((line = bi.readLine()) != null) {
@@ -234,7 +239,9 @@ private static long getSizeOfPhysicalMemoryForWindows() {
234239
try {
235240
Process proc = Runtime.getRuntime().exec("wmic memorychip get capacity");
236241

237-
bi = new BufferedReader(new InputStreamReader(proc.getInputStream()));
242+
bi =
243+
new BufferedReader(
244+
new InputStreamReader(proc.getInputStream(), StandardCharsets.UTF_8));
238245

239246
String line = bi.readLine();
240247
if (line == null) {

0 commit comments

Comments
 (0)