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 1a6bf13612fca..b4ac124fee0ac 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 @@ -16,6 +16,7 @@ */ package org.apache.camel.component.azure.storage.blob; +import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; @@ -46,10 +47,14 @@ public static BlobStreamAndLength createBlobStreamAndLengthFromExchangeBody(fina } 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) { - return new BlobStreamAndLength(new FileInputStream((File) body), ((File) body).length()); + return new BlobStreamAndLength(new BufferedInputStream(new FileInputStream((File) body)), ((File) body).length()); } if (body instanceof byte[]) { return new BlobStreamAndLength(new ByteArrayInputStream((byte[]) body), ((byte[]) body).length);