camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/3] camel git commit: Same fix in camel-zipfile as we recently did in camel-tarfile.
Date Thu, 24 Mar 2016 12:20:31 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x d4d61aecc -> 2fa5943e5
  refs/heads/camel-2.17.x 91f7d4146 -> 58ee935ee
  refs/heads/master 3680450e4 -> d7e76880b


Same fix in camel-zipfile as we recently did in camel-tarfile.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d7e76880
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d7e76880
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d7e76880

Branch: refs/heads/master
Commit: d7e76880be0c0635ad2e4ba108fac47f8c35b539
Parents: 3680450
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Mar 24 13:19:20 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Mar 24 13:19:20 2016 +0100

----------------------------------------------------------------------
 .../camel/dataformat/zipfile/ZipIterator.java   | 60 +++++++++++---------
 .../zipfile/ZipSplitterRouteIssueTest.java      | 13 ++---
 2 files changed, 38 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d7e76880/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
----------------------------------------------------------------------
diff --git a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
index 998bee1..ed8e68e 100644
--- a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
+++ b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
@@ -17,6 +17,7 @@
 package org.apache.camel.dataformat.zipfile;
 
 import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
@@ -40,8 +41,8 @@ public class ZipIterator implements Iterator<Message>, Closeable {
     static final Logger LOGGER = LoggerFactory.getLogger(ZipIterator.class);
     
     private final Message inputMessage;
-    private ZipInputStream zipInputStream;
-    private Message parent;
+    private volatile ZipInputStream zipInputStream;
+    private volatile Message parent;
     
     public ZipIterator(Message inputMessage) {
         this.inputMessage = inputMessage;
@@ -64,12 +65,12 @@ public class ZipIterator implements Iterator<Message>, Closeable
{
             if (!availableDataInCurrentEntry) {
                 // advance to the next entry.
                 parent = getNextElement();
-                // check if there are more data.
-                availableDataInCurrentEntry = zipInputStream.available() == 1;
-                // if there are not more data, close the stream.
-                if (!availableDataInCurrentEntry) {
+                if (parent == null) {
                     zipInputStream.close();
-                }                
+                    availableDataInCurrentEntry = false;
+                } else {
+                    availableDataInCurrentEntry = true;
+                }
             }
             return availableDataInCurrentEntry;            
         } catch (IOException exception) {
@@ -91,30 +92,34 @@ public class ZipIterator implements Iterator<Message>, Closeable
{
     }
     
     private Message getNextElement() {
-        Message answer = null;
+        if (zipInputStream == null) {
+            return null;
+        }
         
-        if (zipInputStream != null) {
-            try {
-                ZipEntry current = getNextEntry();
+        try {
+            ZipEntry current = getNextEntry();
 
-                if (current != null) {
-                    LOGGER.debug("read zipEntry {}", current.getName());
-                    answer = new DefaultMessage();
-                    answer.getHeaders().putAll(inputMessage.getHeaders());
-                    answer.setHeader("zipFileName", current.getName());
-                    answer.setHeader(Exchange.FILE_NAME, current.getName());
+            if (current != null) {
+                LOGGER.debug("read zipEntry {}", current.getName());
+                Message answer = new DefaultMessage();
+                answer.getHeaders().putAll(inputMessage.getHeaders());
+                answer.setHeader("zipFileName", current.getName());
+                answer.setHeader(Exchange.FILE_NAME, current.getName());
+                if (current.getSize() > 0) {
                     answer.setBody(new ZipInputStreamWrapper(zipInputStream));
-                    return answer;
                 } else {
-                    LOGGER.trace("close zipInputStream");
+                    // Workaround for the case when the entry is zero bytes big
+                    answer.setBody(new ByteArrayInputStream(new byte[0]));
                 }
-            } catch (IOException exception) {
-                //Just wrap the IOException as CamelRuntimeException
-                throw new RuntimeCamelException(exception);
+                return answer;
+            } else {
+                LOGGER.trace("close zipInputStream");
+                return null;
             }
-        }        
-        
-        return answer;
+        } catch (IOException exception) {
+            //Just wrap the IOException as CamelRuntimeException
+            throw new RuntimeCamelException(exception);
+        }
     }
 
     public void checkNullAnswer(Message answer) {
@@ -143,8 +148,7 @@ public class ZipIterator implements Iterator<Message>, Closeable
{
 
     @Override
     public void close() throws IOException {
-        if (zipInputStream != null) {
-            zipInputStream.close();
-        }
+        IOHelper.close(zipInputStream);
+        zipInputStream = null;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/d7e76880/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipSplitterRouteIssueTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipSplitterRouteIssueTest.java
b/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipSplitterRouteIssueTest.java
index 36273ae..f23aed8 100644
--- a/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipSplitterRouteIssueTest.java
+++ b/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipSplitterRouteIssueTest.java
@@ -32,9 +32,9 @@ public class ZipSplitterRouteIssueTest extends CamelTestSupport {
 
     @Test
     public void testSplitter() throws Exception {
-        getMockEndpoint("mock:entry").expectedMessageCount(3);
+        getMockEndpoint("mock:entry").expectedMessageCount(2);
 
-        template.sendBody("seda:decompressFiles", new File("src/test/resources/data.zip"));
+        template.sendBody("direct:decompressFiles", new File("src/test/resources/data.zip"));
 
         assertMockEndpointsSatisfied();
     }
@@ -43,11 +43,11 @@ public class ZipSplitterRouteIssueTest extends CamelTestSupport {
     public void testSplitterWithWrongFile() throws Exception {
         getMockEndpoint("mock:entry").expectedMessageCount(0);
         getMockEndpoint("mock:errors").expectedMessageCount(1);
+
         //Send a file which is not exit
-        template.sendBody("seda:decompressFiles", new File("src/test/resources/data"));
+        template.sendBody("direct:decompressFiles", new File("src/test/resources/data"));
         
         assertMockEndpointsSatisfied();
-        
     }
 
     @Override
@@ -57,11 +57,10 @@ public class ZipSplitterRouteIssueTest extends CamelTestSupport {
             public void configure() throws Exception {
                 errorHandler(deadLetterChannel("mock:errors"));
                 
-                from("seda:decompressFiles")
+                from("direct:decompressFiles")
                     .split(new ZipSplitter()).streaming().shareUnitOfWork()
-                        .log("we are splitting")
+                        .to("log:entry")
                         .to("mock:entry");
-                        //.to("file:target/zip/?fileName=decompressed.txt&fileExist=Append");
             }
         };
     }


Mime
View raw message