This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch io in repository https://gitbox.apache.org/repos/asf/camel.git
commit ebd68ef3f90695ba09b8ed1099a9f44c955b3e2d Author: Claus Ibsen <[email protected]> AuthorDate: Tue Feb 4 16:27:19 2025 +0100 CAMEL-21711: camel-core - IOConverter file/path to string should handle binary files --- .../main/java/org/apache/camel/converter/IOConverter.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java b/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java index 7256877bb7f..a1e9b66edcb 100644 --- a/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java +++ b/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java @@ -39,6 +39,7 @@ import java.io.StringReader; import java.io.Writer; import java.net.URL; import java.nio.ByteBuffer; +import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.util.Iterator; @@ -177,7 +178,17 @@ public final class IOConverter { @Converter(order = 22) public static String toString(Path file, Exchange exchange) throws IOException { - return Files.readString(file, ExchangeHelper.getCharset(exchange)); + Charset cs = ExchangeHelper.getCharset(exchange, false); + if (cs != null) { + return Files.readString(file, cs); + } else { + byte[] arr = Files.readAllBytes(file); + if (arr.length == 0) { + return ""; + } else { + return new String(arr); + } + } } @Converter(order = 23)
