You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pa...@apache.org on 2020/03/29 14:18:25 UTC
[camel] branch master updated: Simplify IOHelper#newStringFromBytes
by using StandardCharsets.UTF_8.
This is an automated email from the ASF dual-hosted git repository.
pascalschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new f0f349c Simplify IOHelper#newStringFromBytes by using StandardCharsets.UTF_8.
f0f349c is described below
commit f0f349cf6407ef549f74c78503d2ad9784d27248
Author: Pascal Schumacher <pa...@gmx.net>
AuthorDate: Sun Mar 29 16:18:02 2020 +0200
Simplify IOHelper#newStringFromBytes by using StandardCharsets.UTF_8.
---
.../src/main/java/org/apache/camel/util/IOHelper.java | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java
index a0b79f7..f6a5e25 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java
@@ -40,6 +40,7 @@ import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
import java.util.function.Supplier;
@@ -56,7 +57,6 @@ public final class IOHelper {
public static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
private static final Logger LOG = LoggerFactory.getLogger(IOHelper.class);
- private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
// allows to turn on backwards compatible to turn off regarding the first
// read byte with value zero (0b0) as EOL.
@@ -72,11 +72,7 @@ public final class IOHelper {
* non-standard default encodings.
*/
public static String newStringFromBytes(byte[] bytes) {
- try {
- return new String(bytes, UTF8_CHARSET.name());
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException("Impossible failure: Charset.forName(\"UTF-8\") returns invalid name.", e);
- }
+ return new String(bytes, StandardCharsets.UTF_8);
}
/**
@@ -84,11 +80,7 @@ public final class IOHelper {
* surprises from non-standard default encodings.
*/
public static String newStringFromBytes(byte[] bytes, int start, int length) {
- try {
- return new String(bytes, start, length, UTF8_CHARSET.name());
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException("Impossible failure: Charset.forName(\"UTF-8\") returns invalid name.", e);
- }
+ return new String(bytes, start, length, StandardCharsets.UTF_8);
}
/**