Repository: camel Updated Branches: refs/heads/master cd11f2d06 -> af4902b36
[CAMEL-10876] BlobInputStrean should be available to the producers like File Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c6e58c83 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c6e58c83 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c6e58c83 Branch: refs/heads/master Commit: c6e58c830cb57d22e38d75fc9036433f5eef4818 Parents: 451887e Author: Sergey Beryozkin <sberyoz...@gmail.com> Authored: Fri Feb 17 17:02:45 2017 +0000 Committer: Sergey Beryozkin <sberyoz...@gmail.com> Committed: Fri Feb 17 17:02:45 2017 +0000 ---------------------------------------------------------------------- .../component/azure/blob/BlobServiceUtil.java | 45 +++++++++++--------- .../blob/BlobServiceBlockConsumerTest.java | 5 ++- 2 files changed, 30 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/c6e58c83/components/camel-azure/src/main/java/org/apache/camel/component/azure/blob/BlobServiceUtil.java ---------------------------------------------------------------------- diff --git a/components/camel-azure/src/main/java/org/apache/camel/component/azure/blob/BlobServiceUtil.java b/components/camel-azure/src/main/java/org/apache/camel/component/azure/blob/BlobServiceUtil.java index d00dd4d..c4a4363 100644 --- a/components/camel-azure/src/main/java/org/apache/camel/component/azure/blob/BlobServiceUtil.java +++ b/components/camel-azure/src/main/java/org/apache/camel/component/azure/blob/BlobServiceUtil.java @@ -18,6 +18,7 @@ package org.apache.camel.component.azure.blob; import java.io.File; import java.io.FileOutputStream; +import java.io.InputStream; import java.io.OutputStream; import java.net.URI; @@ -81,38 +82,44 @@ public final class BlobServiceUtil { BlobServiceUtil.configureCloudBlobForRead(client, cfg); BlobServiceRequestOptions opts = getRequestOptions(exchange); LOG.trace("Getting a blob [{}] from exchange [{}]...", cfg.getBlobName(), exchange); - Long blobOffset = cfg.getBlobOffset(); - Long blobDataLength = cfg.getDataLength(); - if (client instanceof CloudPageBlob) { - PageRange range = exchange.getIn().getHeader(BlobServiceConstants.PAGE_BLOB_RANGE, PageRange.class); - if (range != null) { - blobOffset = range.getStartOffset(); - blobDataLength = range.getEndOffset() - range.getStartOffset(); - } - } OutputStream os = exchange.getIn().getBody(OutputStream.class); if (os == null) { String fileDir = cfg.getFileDir(); if (fileDir != null) { - // Should the range if it is set be reflected in the file name ? - String name = cfg.getBlobName(); - File file = new File(fileDir, name + ".blob"); + File file = new File(fileDir, getBlobFileName(cfg)); ExchangeUtil.getMessageForResponse(exchange).setBody(file); - os = new FileOutputStream(file); + os = new FileOutputStream(file); } } - if (os == null) { - throw new IllegalArgumentException("OutputStream is not available"); - } try { - client.downloadRange(blobOffset, blobDataLength, os, - opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext()); + if (os == null) { + // Let the producers like file: deal with it + InputStream blobStream = client.openInputStream( + opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext()); + exchange.getIn().setBody(blobStream); + exchange.getIn().setHeader(Exchange.FILE_NAME, getBlobFileName(cfg)); + } else { + Long blobOffset = cfg.getBlobOffset(); + Long blobDataLength = cfg.getDataLength(); + if (client instanceof CloudPageBlob) { + PageRange range = exchange.getIn().getHeader(BlobServiceConstants.PAGE_BLOB_RANGE, PageRange.class); + if (range != null) { + blobOffset = range.getStartOffset(); + blobDataLength = range.getEndOffset() - range.getStartOffset(); + } + } + client.downloadRange(blobOffset, blobDataLength, os, + opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext()); + } } finally { - if (cfg.isCloseStreamAfterRead()) { + if (os != null && cfg.isCloseStreamAfterRead()) { os.close(); } } } + private static String getBlobFileName(BlobServiceConfiguration cfg) { + return cfg.getBlobName() + ".blob"; + } public static CloudBlobContainer createBlobContainerClient(BlobServiceConfiguration cfg) throws Exception { http://git-wip-us.apache.org/repos/asf/camel/blob/c6e58c83/components/camel-azure/src/test/java/org/apache/camel/component/azure/blob/BlobServiceBlockConsumerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-azure/src/test/java/org/apache/camel/component/azure/blob/BlobServiceBlockConsumerTest.java b/components/camel-azure/src/test/java/org/apache/camel/component/azure/blob/BlobServiceBlockConsumerTest.java index d47b652..c5718d5 100644 --- a/components/camel-azure/src/test/java/org/apache/camel/component/azure/blob/BlobServiceBlockConsumerTest.java +++ b/components/camel-azure/src/test/java/org/apache/camel/component/azure/blob/BlobServiceBlockConsumerTest.java @@ -84,7 +84,10 @@ public class BlobServiceBlockConsumerTest extends CamelTestSupport { from("azure-blob://camelazure/container1/blobBlock?credentials=#creds&fileDir=" + System.getProperty("java.io.tmpdir")).to("mock:result"); + + //from("azure-blob://camelazure/container1/blobBlock?credentials=#creds") + // .to("file://" + System.getProperty("java.io.tmpdir")); } }; } -} \ No newline at end of file +}