This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 26097b73ca35fdff1bbfcf9afb6003fb2b8845ba Author: Andrea Cosentino <[email protected]> AuthorDate: Wed Mar 3 08:31:29 2021 +0100 CAMEL-16277 - Camel-File: Use appendChar for the first message too --- .../main/java/org/apache/camel/component/file/FileOperations.java | 6 ++---- .../org/apache/camel/component/file/FileProduceAppendCharsTest.java | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) 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 af34501..b0a6898 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 @@ -443,7 +443,6 @@ public class FileOperations implements GenericFileOperations<File> { } private void writeFileByStream(InputStream in, File target) throws IOException { - boolean exists = target.exists(); try (SeekableByteChannel out = prepareOutputFileChannel(target)) { LOG.debug("Using InputStream to write file: {}", target); @@ -464,7 +463,7 @@ public class FileOperations implements GenericFileOperations<File> { } boolean append = endpoint.getFileExist() == GenericFileExist.Append; - if (append && exists && endpoint.getAppendChars() != null) { + if (append && endpoint.getAppendChars() != null) { byteBuffer = ByteBuffer.wrap(endpoint.getAppendChars().getBytes()); out.write(byteBuffer); // to be compatible with java 8 @@ -478,7 +477,6 @@ public class FileOperations implements GenericFileOperations<File> { } private void writeFileByReaderWithCharset(Reader in, File target, String charset) throws IOException { - boolean exists = target.exists(); boolean append = endpoint.getFileExist() == GenericFileExist.Append; try (Writer out = Files.newBufferedWriter(target.toPath(), Charset.forName(charset), StandardOpenOption.WRITE, append ? StandardOpenOption.APPEND : StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE)) { @@ -486,7 +484,7 @@ public class FileOperations implements GenericFileOperations<File> { int size = endpoint.getBufferSize(); IOHelper.copy(in, out, size); - if (append && exists && endpoint.getAppendChars() != null) { + if (append && endpoint.getAppendChars() != null) { out.write(endpoint.getAppendChars()); } } finally { diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsTest.java index 08d6e4a..ba20495 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsTest.java @@ -31,9 +31,10 @@ public class FileProduceAppendCharsTest extends ContextTestSupport { @Test public void testAppendChars() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedMessageCount(2); + mock.expectedMessageCount(3); mock.expectedFileExists("target/data/test-file-append/hello.txt", "Hello\nWorld\nHow are you?\n"); + template.sendBody("direct:start", "Hello"); template.sendBody("direct:start", "World"); template.sendBody("direct:start", "How are you?"); @@ -45,7 +46,6 @@ public class FileProduceAppendCharsTest extends ContextTestSupport { public void setUp() throws Exception { deleteDirectory("target/data/test-file-append"); super.setUp(); - template.sendBodyAndHeader("file://target/data/test-file-append", "Hello\n", Exchange.FILE_NAME, "hello.txt"); } @Override
