fabriziofortino commented on code in PR #893:
URL: https://github.com/apache/jackrabbit-oak/pull/893#discussion_r1162529785


##########
oak-run/src/main/java/org/apache/jackrabbit/oak/run/Downloader.java:
##########
@@ -175,19 +172,18 @@ public ItemResponse call() throws Exception {
 
             Path destinationPath = Paths.get(item.destination);
             Files.createDirectories(destinationPath.getParent());
+
             long size = 0;
-            try (ReadableByteChannel byteChannel = 
Channels.newChannel(sourceUrl.getInputStream());
-                 FileChannel outputChannel = FileChannel.open(destinationPath, 
StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
-                ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
+            try (InputStream inputStream = sourceUrl.getInputStream();
+                 FileOutputStream outputStream = new 
FileOutputStream(destinationPath.toFile())) {
+                byte[] buffer = new byte[bufferSize];
                 int bytesRead;
-                while ((bytesRead = byteChannel.read(buffer)) != -1) {
-                    buffer.flip();
+                while ((bytesRead = inputStream.read(buffer)) != -1) {
                     if (md != null) {
-                        md.update(buffer);
+                        md.update(buffer, 0, bytesRead);

Review Comment:
   I agree but this would complicate the logic. An even better option could be 
to use multiple blocking queues where we put the buffer. We can then have 
separate downstream consumer threads (eg: one for writing the file, and another 
to compute the checksum). In this way, we can actually decouple the reads from 
the writes further boosting performance. Complexity will obviously increase. A 
reactive library might help here.



-- 
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