You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/09/25 18:08:55 UTC

[camel] branch camel-3.4.x updated: CAMEL-15526: Camel-AWS2-S3: Consume Gzip file from S3 not working

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

acosentino pushed a commit to branch camel-3.4.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.4.x by this push:
     new 92dd5b1  CAMEL-15526: Camel-AWS2-S3: Consume Gzip file from S3 not working
92dd5b1 is described below

commit 92dd5b142bfe9760334cfaf97a7d6acda10897e9
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Fri Sep 25 15:59:51 2020 +0200

    CAMEL-15526: Camel-AWS2-S3: Consume Gzip file from S3 not working
---
 .../camel/component/aws2/s3/AWS2S3Endpoint.java    | 23 ++++------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java b/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
index b509b8d..fa0e7fc 100644
--- a/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
+++ b/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
@@ -16,12 +16,7 @@
  */
 package org.apache.camel.component.aws2.s3;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
 
 import org.apache.camel.Category;
 import org.apache.camel.Component;
@@ -32,6 +27,7 @@ import org.apache.camel.ExtendedExchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.aws2.s3.client.AWS2S3ClientFactory;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
@@ -50,6 +46,7 @@ import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
 import software.amazon.awssdk.services.s3.model.GetObjectResponse;
 import software.amazon.awssdk.services.s3.model.ListObjectsRequest;
 import software.amazon.awssdk.services.s3.model.PutBucketPolicyRequest;
+import software.amazon.awssdk.utils.IoUtils;
 
 /**
  * Store and retrie objects from AWS S3 Storage Service using AWS SDK version 2.x.
@@ -168,10 +165,9 @@ public class AWS2S3Endpoint extends ScheduledPollEndpoint {
 
         if (configuration.isIncludeBody()) {
             try {
-                message.setBody(readInputStream(s3Object));
+                message.setBody(IoUtils.toByteArray(s3Object));
             } catch (IOException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
+                throw new RuntimeCamelException(e);
             }
         } else {
             message.setBody(null);
@@ -255,15 +251,4 @@ public class AWS2S3Endpoint extends ScheduledPollEndpoint {
     public void setMaxConnections(int maxConnections) {
         this.maxConnections = maxConnections;
     }
-
-    private String readInputStream(ResponseInputStream<GetObjectResponse> s3Object) throws IOException {
-        StringBuilder textBuilder = new StringBuilder();
-        try (Reader reader = new BufferedReader(new InputStreamReader(s3Object, Charset.forName(StandardCharsets.UTF_8.name())))) {
-            int c = 0;
-            while ((c = reader.read()) != -1) {
-                textBuilder.append((char)c);
-            }
-        }
-        return textBuilder.toString();
-    }
 }