From 98fb88508e27a4859bbfc574d3619f092c9f711c Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Tue, 28 Dec 2021 10:51:27 -0800 Subject: [PATCH] Make TextFile internally consistent --- core/src/main/java/hudson/util/TextFile.java | 13 ++++++++----- core/src/test/java/hudson/util/TextFileTest.java | 7 ++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/hudson/util/TextFile.java b/core/src/main/java/hudson/util/TextFile.java index 78e5716c05b0..8a6c990442dd 100644 --- a/core/src/main/java/hudson/util/TextFile.java +++ b/core/src/main/java/hudson/util/TextFile.java @@ -61,7 +61,8 @@ public void delete() throws IOException { } /** - * Reads the entire contents and returns it. + * Reads the entire contents and returns it. Bytes from the file are decoded into characters + * using the {@link StandardCharsets#UTF_8 UTF-8} {@link Charset charset}. */ public String read() throws IOException { StringWriter out = new StringWriter(); @@ -107,12 +108,13 @@ public void write(String text) throws IOException { } /** - * Reads the first N characters or until we hit EOF. + * Reads the first N characters or until we hit EOF. Bytes from the file are decoded into + * characters using the {@link StandardCharsets#UTF_8 UTF-8} {@link Charset charset}. */ public @NonNull String head(int numChars) throws IOException { char[] buf = new char[numChars]; int read = 0; - try (Reader r = Files.newBufferedReader(Util.fileToPath(file), Charset.defaultCharset())) { + try (Reader r = Files.newBufferedReader(Util.fileToPath(file), StandardCharsets.UTF_8)) { while (read