You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "graben (via GitHub)" <gi...@apache.org> on 2023/12/01 06:26:17 UTC

Re: [PR] CAMEL-20172: Add checksum feature to camel-file/ftp [camel]

graben commented on code in PR #12280:
URL: https://github.com/apache/camel/pull/12280#discussion_r1411664078


##########
components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileProducer.java:
##########
@@ -212,6 +215,28 @@ protected void processExchange(Exchange exchange, String target) throws Exceptio
                 }
             }
 
+            // any checksum file to write?
+            if (endpoint.getChecksumFileAlgorithm() != null) {
+                String algorithm = endpoint.getChecksumFileAlgorithm();
+                String checksumFileName = target + "." + algorithm;
+
+                // create exchange with checksum as body to write as the checksum file
+                MessageHelper.resetStreamCache(exchange.getIn());
+                InputStream is = exchange.getIn().getMandatoryBody(InputStream.class);
+                Exchange checksumExchange = new DefaultExchange(exchange);
+                checksumExchange.getIn().setBody(new DigestUtils(algorithm).digestAsHex(is));
+
+                LOG.trace("Writing checksum file: [{}]", checksumFileName);
+                // delete any existing done file
+                if (operations.existsFile(checksumFileName)) {
+                    if (!operations.deleteFile(checksumFileName)) {
+                        throw new GenericFileOperationFailedException(
+                                "Cannot delete existing checksum file: " + checksumFileName);
+                    }
+                }
+                writeFile(checksumExchange, checksumFileName);

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org