This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 04f57cb97fd1 CAMEL-24089: camel-file - Loop transferTo to handle files
larger than 2 GB
04f57cb97fd1 is described below
commit 04f57cb97fd122c90833bea7d98ed6fa6ccdb70c
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Jul 16 07:17:27 2026 +0200
CAMEL-24089: camel-file - Loop transferTo to handle files larger than 2 GB
FileChannel.transferTo() may transfer fewer bytes than requested — on
Linux the JDK caps each call at Integer.MAX_VALUE bytes via sendfile(2).
The existing code made a single call and discarded the return value, so
files larger than ~2 GB were silently truncated when using
readLock=fileLock.
Replace the single call with the standard transferTo loop pattern that
tracks position and keeps calling until all bytes are transferred.
Only the readLock=fileLock code path is affected. The non-locked path
uses Files.copy() which handles large files correctly.
Closes #24743
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../main/java/org/apache/camel/component/file/FileOperations.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
index a632579bc527..6bd74b8bdd61 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
@@ -522,7 +522,11 @@ public class FileOperations implements
GenericFileOperations<File> {
try (FileOutputStream fos = new FileOutputStream(target);
FileChannel out = fos.getChannel()) {
LOG.trace("writeFileByFile using FileChannel: {} -> {}",
source, target);
- channel.transferTo(0, channel.size(), out);
+ long size = channel.size();
+ long position = 0;
+ while (position < size) {
+ position += channel.transferTo(position, size - position,
out);
+ }
}
} else {
// use regular file copy