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 17:47:56 UTC

[camel] branch backport-3.4.x created (now 39dcc67)

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

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


      at 39dcc67  CAMEL-15526: Camel-AWS2-S3: Consume Gzip file from S3 not working

This branch includes the following new commits:

     new 39dcc67  CAMEL-15526: Camel-AWS2-S3: Consume Gzip file from S3 not working

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[camel] 01/01: CAMEL-15526: Camel-AWS2-S3: Consume Gzip file from S3 not working

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 39dcc67d6c9d0bc8c555ffd1de55564610c60178
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();
-    }
 }