You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2025/02/04 15:27:52 UTC

(camel) branch io created (now ebd68ef3f90)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch io
in repository https://gitbox.apache.org/repos/asf/camel.git


      at ebd68ef3f90 CAMEL-21711: camel-core - IOConverter file/path to string should handle binary files

This branch includes the following new commits:

     new ebd68ef3f90 CAMEL-21711: camel-core - IOConverter file/path to string should handle binary files

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(camel) 01/01: CAMEL-21711: camel-core - IOConverter file/path to string should handle binary files

Posted by da...@apache.org.
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 <cl...@gmail.com>
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)