CAMEL-10791-only component update
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/928cdb1e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/928cdb1e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/928cdb1e Branch: refs/heads/master Commit: 928cdb1edf7754a990b23d058fced8fd35ed9de6 Parents: c2b2ee2 Author: onders86 <ondersez...@gmail.com> Authored: Mon Mar 13 21:24:47 2017 +0300 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Mar 14 18:29:38 2017 +0100 ---------------------------------------------------------------------- .../dataformat/zipfile/ZipFileDataFormat.java | 6 +- .../camel/dataformat/zipfile/ZipIterator.java | 2 +- .../zipfile/ZipFileDataFormatTest.java | 59 +++++++++++++++++++- 3 files changed, 58 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/928cdb1e/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java index 3704d94..8ae24b2 100644 --- a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java +++ b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java @@ -73,11 +73,7 @@ public class ZipFileDataFormat extends ServiceSupport implements DataFormat, Dat @Override public Object unmarshal(final Exchange exchange, final InputStream inputStream) throws Exception { - if (supportEmptyDirectory) { - exchange.getIn().setHeader("unzipEmptyDirectorySupported", true); - } else { - exchange.getIn().setHeader("unzipEmptyDirectorySupported", false); - } + exchange.getIn().setHeader("unzipEmptyDirectorySupported", isSupportEmptyDirectory()); if (usingIterator) { return new ZipIterator(exchange.getIn()); } else { http://git-wip-us.apache.org/repos/asf/camel/blob/928cdb1e/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 6d58ad8..bd67f8a 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 @@ -133,7 +133,7 @@ public class ZipIterator implements Iterator<Message>, Closeable { return entry; } else { if (unzipEmptyDirectorySupported) { - ZipEntry dirEntry = new ZipEntry(entry.getName() + "."); + ZipEntry dirEntry = new ZipEntry(entry.getName()); return dirEntry; } } http://git-wip-us.apache.org/repos/asf/camel/blob/928cdb1e/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java ---------------------------------------------------------------------- diff --git a/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java b/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java index e4cecb3..6afac67 100644 --- a/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java +++ b/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java @@ -20,15 +20,20 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Iterator; import java.util.concurrent.TimeUnit; import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; import org.apache.camel.Exchange; +import org.apache.camel.Processor; import org.apache.camel.builder.NotifyBuilder; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; @@ -115,7 +120,7 @@ public class ZipFileDataFormatTest extends CamelTestSupport { zip.setSupportEmptyDirectory(true); template.sendBody("direct:unzipWithEmptyDirectory", new File("src/test/resources/hello.odt")); assertTrue(Files.exists(Paths.get("hello_out/Configurations2"))); - deleteDirectory(new File("hello_out")); + //deleteDirectory(new File("hello_out")); } @Test @@ -125,7 +130,7 @@ public class ZipFileDataFormatTest extends CamelTestSupport { zip.setSupportEmptyDirectory(false); template.sendBody("direct:unzipWithEmptyDirectory", new File("src/test/resources/hello.odt")); assertTrue(!Files.exists(Paths.get("hello_out/Configurations2"))); - deleteDirectory(new File("hello_out")); + //deleteDirectory(new File("hello_out")); } @Test @@ -212,6 +217,35 @@ public class ZipFileDataFormatTest extends CamelTestSupport { deleteDirectory(TEST_DIR); super.setUp(); } + + private static void copy(InputStream in, OutputStream out) throws IOException { + byte[] buffer = new byte[1024]; + while (true) { + int readCount = in.read(buffer); + if (readCount < 0) { + break; + } + out.write(buffer, 0, readCount); + } + } + + private static void copy(File file, OutputStream out) throws IOException { + InputStream in = new FileInputStream(file); + try { + copy(in, out); + } finally { + in.close(); + } + } + + private static void copy(InputStream in, File file) throws IOException { + OutputStream out = new FileOutputStream(file); + try { + copy(in, out); + } finally { + out.close(); + } + } @Override protected RouteBuilder createRouteBuilder() throws Exception { @@ -227,7 +261,26 @@ public class ZipFileDataFormatTest extends CamelTestSupport { from("direct:unzipWithEmptyDirectory").unmarshal(zip) .split(body(Iterator.class)) .streaming() - .to("file:hello_out?autoCreate=true") + //.to("file:hello_out?autoCreate=true") + .process(new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + ZipFile zfile = new ZipFile(new File("src/test/resources/hello.odt")); + ZipEntry entry = new ZipEntry((String)exchange.getIn().getHeader(Exchange.FILE_NAME)); + File file = new File("hello_out", entry.getName()); + if (entry.isDirectory()) { + file.mkdirs(); + } else { + file.getParentFile().mkdirs(); + InputStream in = zfile.getInputStream(entry); + try { + copy(in, file); + } finally { + in.close(); + } + } + } + }) .end(); from("direct:zipAndUnzip").marshal(zip).unmarshal(zip).to("mock:zipAndUnzip"); from("direct:zipToFile").marshal(zip).to("file:" + TEST_DIR.getPath()).to("mock:zipToFile");