This is an automated email from the ASF dual-hosted git repository. oalsafi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new f3199fc CAMEL-16252: Remove the explicit stream mark check (#5138) f3199fc is described below commit f3199fc1804f98ef47d0ad51134c480f6949ffa5 Author: Omar Al-Safi <omars...@gmail.com> AuthorDate: Fri Feb 26 12:21:23 2021 +0100 CAMEL-16252: Remove the explicit stream mark check (#5138) --- .../azure/storage/blob/BlobStreamAndLength.java | 4 ---- .../component/azure/storage/blob/BlobUtils.java | 4 ---- .../blob/integration/BlobOperationsITTest.java | 28 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobStreamAndLength.java b/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobStreamAndLength.java index da0595a..a38a604 100644 --- a/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobStreamAndLength.java +++ b/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobStreamAndLength.java @@ -47,10 +47,6 @@ public final class BlobStreamAndLength { } if (body instanceof InputStream) { - // Note: InputStream has to support mark/reset operations - if (!((InputStream) body).markSupported()) { - throw new IllegalArgumentException("InputStream of body exchange does not support mark/rest operations."); - } return new BlobStreamAndLength((InputStream) body, BlobUtils.getInputStreamLength((InputStream) body)); } if (body instanceof File) { diff --git a/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobUtils.java b/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobUtils.java index 4a2c702..02ada37 100644 --- a/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobUtils.java +++ b/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobUtils.java @@ -34,10 +34,6 @@ public final class BlobUtils { } public static Long getInputStreamLength(final InputStream inputStream) throws IOException { - if (!inputStream.markSupported()) { - throw new IllegalArgumentException( - "Reset inputStream is not supported, provide an inputstream with supported mark/reset."); - } final long length = IOUtils.toByteArray(inputStream).length; inputStream.reset(); diff --git a/components/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobOperationsITTest.java b/components/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobOperationsITTest.java index 5e4d9a8..fbf60be 100644 --- a/components/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobOperationsITTest.java +++ b/components/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobOperationsITTest.java @@ -43,6 +43,7 @@ import org.apache.camel.component.azure.storage.blob.client.BlobContainerClientW import org.apache.camel.component.azure.storage.blob.client.BlobServiceClientWrapper; import org.apache.camel.component.azure.storage.blob.operations.BlobOperationResponse; import org.apache.camel.component.azure.storage.blob.operations.BlobOperations; +import org.apache.camel.converter.stream.FileInputStreamCache; import org.apache.camel.support.DefaultExchange; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -198,6 +199,33 @@ class BlobOperationsITTest extends BaseIT { } @Test + void testUploadBlockBlobAsCachedStream() throws Exception { + final BlobClientWrapper blobClientWrapper = blobContainerClientWrapper.getBlobClientWrapper("upload_test_file"); + final BlobOperations operations = new BlobOperations(configuration, blobClientWrapper); + + final File fileToUpload + = new File(Objects.requireNonNull(getClass().getClassLoader().getResource("upload_test_file")).getFile()); + final Exchange exchange = new DefaultExchange(context); + exchange.getIn().setBody(new FileInputStreamCache(fileToUpload)); + + final BlobOperationResponse response = operations.uploadBlockBlob(exchange); + + assertNotNull(response); + assertTrue((boolean) response.getBody()); + // check for eTag and md5 to make sure is uploaded + assertNotNull(response.getHeaders().get(BlobConstants.E_TAG)); + assertNotNull(response.getHeaders().get(BlobConstants.CONTENT_MD5)); + + // check content + final BlobOperationResponse getBlobResponse = operations.getBlob(null); + + assertEquals("awesome camel to upload!", + IOUtils.toString((InputStream) getBlobResponse.getBody(), Charset.defaultCharset())); + + blobClientWrapper.delete(null, null, null); + } + + @Test void testCommitAndStageBlockBlob() throws Exception { final BlobClientWrapper blobClientWrapper = blobContainerClientWrapper.getBlobClientWrapper("upload_test_file"); final BlobOperations operations = new BlobOperations(configuration, blobClientWrapper);