You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2022/04/26 10:44:19 UTC

[GitHub] [camel] essobedo commented on a diff in pull request #7493: CAMEL-17861

essobedo commented on code in PR #7493:
URL: https://github.com/apache/camel/pull/7493#discussion_r858562657


##########
components/camel-azure/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobUtils.java:
##########
@@ -33,11 +33,26 @@ public static Message getInMessage(final Exchange exchange) {
         return ObjectHelper.isEmpty(exchange) ? null : exchange.getIn();
     }
 
-    public static Long getInputStreamLength(final InputStream inputStream) throws IOException {
-        final long length = IOUtils.toByteArray(inputStream).length;
-        inputStream.reset();
-
-        return length;
+    public static long getInputStreamLength(InputStream is) throws IOException {
+        if (!is.markSupported()) {
+            return -1;
+        }
+        if (is instanceof ByteArrayInputStream) {
+            return is.available();
+        }
+        long size = 0;
+        try {
+            is.mark(1024);
+            int i = is.available();

Review Comment:
   I'm not sure that relying on the method `available` is really safe especially when we read the Javadoc about it that is quite flexible regarding the implementation



##########
components/camel-azure/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobUtils.java:
##########
@@ -33,11 +33,26 @@ public static Message getInMessage(final Exchange exchange) {
         return ObjectHelper.isEmpty(exchange) ? null : exchange.getIn();
     }
 
-    public static Long getInputStreamLength(final InputStream inputStream) throws IOException {
-        final long length = IOUtils.toByteArray(inputStream).length;
-        inputStream.reset();
-
-        return length;
+    public static long getInputStreamLength(InputStream is) throws IOException {
+        if (!is.markSupported()) {
+            return -1;

Review Comment:
   I'm afraid that returning -1 as length could cause side effects in some parts of the code



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org