joerghoh commented on code in PR #2621:
URL: https://github.com/apache/jackrabbit-oak/pull/2621#discussion_r2559149048


##########
oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java:
##########
@@ -1323,6 +1331,48 @@ private static String getIdentifierName(String key) {
         return key.substring(0, 4) + key.substring(5);
     }
 
+    @NotNull
+    private AsyncRequestBody getRequestBody(final InputStream input, final 
ExecutorService executor,
+                                            final PutObjectRequest.Builder 
builder) throws IOException {
+        final AsyncRequestBody body;
+        if (Objects.equals(RemoteStorageMode.S3, 
properties.get(S3Constants.MODE))) {
+            body = AsyncRequestBody.fromInputStream(input, null, executor);
+        } else {
+            // for GCP we need to know the length in advance, else it won't 
work.
+            final long length;
+            if (input instanceof FileInputStream) {
+                final FileInputStream fis = (FileInputStream) input;
+                // if the file is modified after opening, the size may not 
reflect the latest changes
+                length = fis.getChannel().size();
+                body = AsyncRequestBody.fromInputStream(input, length, 
executor);
+            } else if (input instanceof ByteArrayInputStream) {
+                length = input.available();
+                body = AsyncRequestBody.fromInputStream(input, length, 
executor);
+            } else if (input.markSupported()) {
+                // in case the inputStream supports mark & reset
+                input.mark(Integer.MAX_VALUE);
+                length = IOUtils.consume(input);
+                input.reset();
+                body = AsyncRequestBody.fromInputStream(input, length, 
executor);
+            } else {

Review Comment:
   thinking again about that: Do we really need to store the entire stream on 
disk if we just the length? Can't we consume it in chunks?
   
   ```
   long length = 0;
   byte[] buffer = new byte[2048];
   int sizeRead = buffer.read(buffer);
   while (sizeRead != -1) {
     length+=sizeRead;
     sizeRead = buffer.read(buffer);
   }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to