You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/07/16 12:34:34 UTC
[commons-io] branch master updated: Use a JRE built-in Charset instead of a magic string
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new f0971f8a Use a JRE built-in Charset instead of a magic string
f0971f8a is described below
commit f0971f8af988df7ced7b8fd1d0379f21e30f6e79
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jul 16 08:34:30 2023 -0400
Use a JRE built-in Charset instead of a magic string
---
src/test/java/org/apache/commons/io/input/TeeInputStreamTest.java | 3 ++-
.../commons/io/input/UnsynchronizedBufferedInputStreamTest.java | 3 ++-
.../apache/commons/io/input/UnsynchronizedFilterInputStreamTest.java | 3 ++-
src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java | 5 +++--
4 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/test/java/org/apache/commons/io/input/TeeInputStreamTest.java b/src/test/java/org/apache/commons/io/input/TeeInputStreamTest.java
index 4fdf9824..e7b7391f 100644
--- a/src/test/java/org/apache/commons/io/input/TeeInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/TeeInputStreamTest.java
@@ -28,6 +28,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import org.apache.commons.io.test.ThrowOnCloseInputStream;
import org.apache.commons.io.test.ThrowOnCloseOutputStream;
@@ -39,7 +40,7 @@ import org.junit.jupiter.api.Test;
*/
public class TeeInputStreamTest {
- private final String ASCII = "US-ASCII";
+ private final String ASCII = StandardCharsets.US_ASCII.name();
private InputStream tee;
diff --git a/src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStreamTest.java b/src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStreamTest.java
index 02951f89..8314d745 100644
--- a/src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStreamTest.java
@@ -26,6 +26,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -63,7 +64,7 @@ public class UnsynchronizedBufferedInputStreamTest {
@BeforeEach
protected void setUp() throws IOException {
fileName = Files.createTempFile(getClass().getSimpleName(), ".tst");
- Files.write(fileName, DATA.getBytes("UTF-8"));
+ Files.write(fileName, DATA.getBytes(StandardCharsets.UTF_8));
isFile = Files.newInputStream(fileName);
is = new BufferedInputStream(isFile);
diff --git a/src/test/java/org/apache/commons/io/input/UnsynchronizedFilterInputStreamTest.java b/src/test/java/org/apache/commons/io/input/UnsynchronizedFilterInputStreamTest.java
index ab4e3d94..fd33bee3 100644
--- a/src/test/java/org/apache/commons/io/input/UnsynchronizedFilterInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/UnsynchronizedFilterInputStreamTest.java
@@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -56,7 +57,7 @@ public class UnsynchronizedFilterInputStreamTest {
@BeforeEach
protected void setUp() throws IOException {
fileName = Files.createTempFile(getClass().getSimpleName(), ".tst");
- Files.write(fileName, DATA.getBytes("UTF-8"));
+ Files.write(fileName, DATA.getBytes(StandardCharsets.UTF_8));
is = UnsynchronizedFilterInputStream.builder().setInputStream(Files.newInputStream(fileName)).get();
}
diff --git a/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java b/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
index 026ea4f0..2cfc87f1 100644
--- a/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
+++ b/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
@@ -435,10 +435,11 @@ public class XmlStreamReaderTest {
@Test
@DefaultLocale(language = "tr")
public void testLowerCaseEncodingWithTurkishLocale_IO_557() throws Exception {
- final String[] encodings = {"iso8859-1", "us-ascii", "utf-8"};
+ final String[] encodings = { "iso8859-1", "us-ascii", "utf-8" }; // lower-case
for (final String encoding : encodings) {
final String xml = getXML("no-bom", XML3, encoding, encoding);
- try (ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes(encoding)); XmlStreamReader xmlReader = new XmlStreamReader(is)) {
+ try (ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes(encoding));
+ XmlStreamReader xmlReader = new XmlStreamReader(is)) {
assertTrue(encoding.equalsIgnoreCase(xmlReader.getEncoding()), "Check encoding : " + encoding);
assertEquals(xml, IOUtils.toString(xmlReader), "Check content");
}