DImuthuUpe commented on code in PR #91:
URL: https://github.com/apache/airavata-mft/pull/91#discussion_r1141156866


##########
transport/local-transport/src/main/java/org/apache/airavata/mft/transport/local/LocalIncomingChunkedConnector.java:
##########
@@ -53,45 +55,40 @@ public void failed() throws Exception {
     @Override
     public void downloadChunk(int chunkId, long startByte, long endByte, 
String downloadFile) throws Exception {
 
-        FileInputStream from = new FileInputStream(new 
File(this.resourcePath));
-        FileOutputStream to = new FileOutputStream(new File(downloadFile));
-
-        final int buffLen = 1024;
-
-        byte[] buf = new byte[buffLen];
-
-        from.skip(startByte);
-
-        long fileSize = endByte - startByte + 1;
-
-        while (true) {
-            int bufSize = 0;
-
-            if (buffLen < fileSize) {
-                bufSize = buffLen;
-            } else {
-                bufSize = (int) fileSize;
-            }
-
-            bufSize = (int) from.read(buf, 0, bufSize);
-
-            if (bufSize < 0) {
-                break;
-            }
-
-            to.write(buf, 0, bufSize);
-            to.flush();
-
-            fileSize -= bufSize;
-
-            if (fileSize == 0L) {
-                break;
+        logger.info("Downloading chunk {} with start byte {} and end byte {} 
to file {} from resource path {}",
+                chunkId, startByte, endByte, downloadFile, this.resourcePath);
+
+//        #use this code on a DMA enabled device

Review Comment:
   Make this configurable through a property



##########
transport/local-transport/src/main/java/org/apache/airavata/mft/transport/local/LocalIncomingChunkedConnector.java:
##########
@@ -53,45 +55,40 @@ public void failed() throws Exception {
     @Override
     public void downloadChunk(int chunkId, long startByte, long endByte, 
String downloadFile) throws Exception {
 
-        FileInputStream from = new FileInputStream(new 
File(this.resourcePath));
-        FileOutputStream to = new FileOutputStream(new File(downloadFile));
-
-        final int buffLen = 1024;
-
-        byte[] buf = new byte[buffLen];
-
-        from.skip(startByte);
-
-        long fileSize = endByte - startByte + 1;
-
-        while (true) {
-            int bufSize = 0;
-
-            if (buffLen < fileSize) {
-                bufSize = buffLen;
-            } else {
-                bufSize = (int) fileSize;
-            }
-
-            bufSize = (int) from.read(buf, 0, bufSize);
-
-            if (bufSize < 0) {
-                break;
-            }
-
-            to.write(buf, 0, bufSize);
-            to.flush();
-
-            fileSize -= bufSize;
-
-            if (fileSize == 0L) {
-                break;
+        logger.info("Downloading chunk {} with start byte {} and end byte {} 
to file {} from resource path {}",
+                chunkId, startByte, endByte, downloadFile, this.resourcePath);
+
+//        #use this code on a DMA enabled device
+//        if (resourceSize <= endByte - startByte) {
+//            Files.copy(Path.of(this.resourcePath), Path.of(downloadFile));
+//        } else {
+//            try (FileInputStream from = new 
FileInputStream(this.resourcePath);
+//                 FileOutputStream to = new FileOutputStream(downloadFile)) {
+//                from.getChannel().transferTo(startByte, endByte - startByte, 
to.getChannel());
+//            } catch (Exception e) {
+//                logger.error("Unexpected error occurred while downloading 
chunk {} to file {} from resource path {}",
+//                        chunkId, downloadFile, this.resourcePath, e);
+//                throw e;
+//            }
+//        }
+
+        int buffLen = 1024 * 1024 * 16;

Review Comment:
   Make this a configurable value



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