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-kafka-connector.git
commit 71c04c7b78988af3801e3c2a2d1db6948e58e468 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Mon Dec 14 11:12:57 2020 +0100 Camel-AWS2-S3 connector: Add out of the box specific Aggregation Strategies, added NewlineAggregationStrategy --- .../aggregation/NewlineAggregationStrategy.java | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/connectors/camel-aws2-s3-kafka-connector/src/main/java/org/apache/camel/kafkaconnector/aws2s3/aggregation/NewlineAggregationStrategy.java b/connectors/camel-aws2-s3-kafka-connector/src/main/java/org/apache/camel/kafkaconnector/aws2s3/aggregation/NewlineAggregationStrategy.java new file mode 100644 index 0000000..9c61218 --- /dev/null +++ b/connectors/camel-aws2-s3-kafka-connector/src/main/java/org/apache/camel/kafkaconnector/aws2s3/aggregation/NewlineAggregationStrategy.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.kafkaconnector.aws2s3.aggregation; + +import org.apache.camel.AggregationStrategy; +import org.apache.camel.Exchange; +import org.apache.camel.Message; + +public class NewlineAggregationStrategy implements AggregationStrategy { + + @Override + public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { + // lets append the old body to the new body + if (oldExchange == null) { + return newExchange; + } + + String body = oldExchange.getIn().getBody(String.class); + if (body != null) { + Message newIn = newExchange.getIn(); + String newBody = newIn.getBody(String.class); + if (newBody != null) { + body += System.lineSeparator() + newBody; + } + + newIn.setBody(body); + } + return newExchange; + } +}