This is an automated email from the ASF dual-hosted git repository.

hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new 4d12bef752 File compare does not work for cloud objects, fixes #6486 
(#6487)
4d12bef752 is described below

commit 4d12bef7522a3b298a4dd54ea74d7b1406187f06
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Mon Feb 2 13:39:09 2026 +0100

    File compare does not work for cloud objects, fixes #6486 (#6487)
---
 .../actions/filecompare/ActionFileCompare.java     | 66 +++++++------------
 .../folderscompare/ActionFoldersCompare.java       | 77 +++++++++-------------
 2 files changed, 53 insertions(+), 90 deletions(-)

diff --git 
a/plugins/actions/filecompare/src/main/java/org/apache/hop/workflow/actions/filecompare/ActionFileCompare.java
 
b/plugins/actions/filecompare/src/main/java/org/apache/hop/workflow/actions/filecompare/ActionFileCompare.java
index fda41c69bd..52e96a51bc 100644
--- 
a/plugins/actions/filecompare/src/main/java/org/apache/hop/workflow/actions/filecompare/ActionFileCompare.java
+++ 
b/plugins/actions/filecompare/src/main/java/org/apache/hop/workflow/actions/filecompare/ActionFileCompare.java
@@ -18,8 +18,8 @@
 package org.apache.hop.workflow.actions.filecompare;
 
 import java.io.BufferedInputStream;
-import java.io.DataInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.List;
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileType;
@@ -109,51 +109,33 @@ public class ActionFileCompare extends ActionBase 
implements Cloneable, IAction
    * @throws org.apache.hop.core.exception.HopFileException upon IO problems
    */
   protected boolean equalFileContents(FileObject file1, FileObject file2) 
throws HopFileException {
-    // Really read the contents and do comparisons
-    DataInputStream in1 = null;
-    DataInputStream in2 = null;
-    try {
-      in1 =
-          new DataInputStream(
-              new BufferedInputStream(
-                  HopVfs.getInputStream(HopVfs.getFilename(file1), 
getVariables())));
-      in2 =
-          new DataInputStream(
-              new BufferedInputStream(
-                  HopVfs.getInputStream(HopVfs.getFilename(file2), 
getVariables())));
+    // Really read the contents and do comparisons.
+    try (InputStream in1 =
+            new BufferedInputStream(
+                HopVfs.getInputStream(HopVfs.getFilename(file1), 
getVariables()));
+        InputStream in2 =
+            new BufferedInputStream(
+                HopVfs.getInputStream(HopVfs.getFilename(file2), 
getVariables()))) {
 
-      char ch1;
-      char ch2;
-      while (in1.available() != 0 && in2.available() != 0) {
-        ch1 = (char) in1.readByte();
-        ch2 = (char) in2.readByte();
-        if (ch1 != ch2) {
+      int b1;
+      int b2;
+      while (true) {
+        b1 = in1.read();
+        b2 = in2.read();
+        if (b1 == -1 || b2 == -1) {
+          break;
+        }
+        if (b1 != b2) {
           return false;
         }
       }
-      if (in1.available() != in2.available()) {
-        return false;
-      } else {
-        return true;
-      }
+      // Both streams must be at EOF for files to be equal
+      return b1 == -1 && b2 == -1;
     } catch (IOException e) {
       throw new HopFileException(e);
-    } finally {
-      if (in1 != null) {
-        try {
-          in1.close();
-        } catch (IOException ignored) {
-          // Nothing to do here
-        }
-      }
-      if (in2 != null) {
-        try {
-          in2.close();
-        } catch (IOException ignored) {
-          // Nothing to see here...
-        }
-      }
     }
+    // Nothing to do here
+    // Nothing to see here...
   }
 
   @Override
@@ -173,11 +155,7 @@ public class ActionFileCompare extends ActionBase 
implements Cloneable, IAction
         file2 = HopVfs.getFileObject(realFilename2, getVariables());
 
         if (file1.exists() && file2.exists()) {
-          if (equalFileContents(file1, file2)) {
-            result.setResult(true);
-          } else {
-            result.setResult(false);
-          }
+          result.setResult(equalFileContents(file1, file2));
 
           // add filename to result filenames
           if (addFilenameToResult
diff --git 
a/plugins/actions/folderscompare/src/main/java/org/apache/hop/workflow/actions/folderscompare/ActionFoldersCompare.java
 
b/plugins/actions/folderscompare/src/main/java/org/apache/hop/workflow/actions/folderscompare/ActionFoldersCompare.java
index e001937e26..0ba1a90659 100644
--- 
a/plugins/actions/folderscompare/src/main/java/org/apache/hop/workflow/actions/folderscompare/ActionFoldersCompare.java
+++ 
b/plugins/actions/folderscompare/src/main/java/org/apache/hop/workflow/actions/folderscompare/ActionFoldersCompare.java
@@ -18,8 +18,8 @@
 package org.apache.hop.workflow.actions.folderscompare;
 
 import java.io.BufferedInputStream;
-import java.io.DataInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -198,49 +198,33 @@ public class ActionFoldersCompare extends ActionBase 
implements Cloneable, IActi
    * @throws org.apache.hop.core.exception.HopFileException upon IO problems
    */
   protected boolean equalFileContents(FileObject file1, FileObject file2) 
throws HopFileException {
-    // Really read the contents and do comparisons
-    DataInputStream in1 = null;
-    DataInputStream in2 = null;
-    try {
-      // Really read the contents and do comparisons
-
-      in1 =
-          new DataInputStream(
-              new BufferedInputStream(
-                  HopVfs.getInputStream(HopVfs.getFilename(file1), 
getVariables())));
-      in2 =
-          new DataInputStream(
-              new BufferedInputStream(
-                  HopVfs.getInputStream(HopVfs.getFilename(file2), 
getVariables())));
-
-      char ch1;
-      char ch2;
-      while (in1.available() != 0 && in2.available() != 0) {
-        ch1 = (char) in1.readByte();
-        ch2 = (char) in2.readByte();
-        if (ch1 != ch2) {
+    // Really read the contents and do comparisons.
+    try (InputStream in1 =
+            new BufferedInputStream(
+                HopVfs.getInputStream(HopVfs.getFilename(file1), 
getVariables()));
+        InputStream in2 =
+            new BufferedInputStream(
+                HopVfs.getInputStream(HopVfs.getFilename(file2), 
getVariables()))) {
+
+      int b1;
+      int b2;
+      while (true) {
+        b1 = in1.read();
+        b2 = in2.read();
+        if (b1 == -1 || b2 == -1) {
+          break;
+        }
+        if (b1 != b2) {
           return false;
         }
       }
-      return in1.available() == in2.available();
+      // Both streams must be at EOF for files to be equal
+      return b1 == -1 && b2 == -1;
     } catch (IOException e) {
       throw new HopFileException(e);
-    } finally {
-      if (in1 != null) {
-        try {
-          in1.close();
-        } catch (IOException ignored) {
-          // Nothing to see here...
-        }
-      }
-      if (in2 != null) {
-        try {
-          in2.close();
-        } catch (Exception ignored) {
-          // We can't do anything else here...
-        }
-      }
     }
+    // Nothing to see here...
+    // We can't do anything else here...
   }
 
   @Override
@@ -542,14 +526,15 @@ public class ActionFoldersCompare extends ActionBase 
implements Cloneable, IActi
             }
           } else {
             // Not in the Base Folder...Only if include sub folders
-            if (includesubfolders) {
-              if ((info.getFile().getType() == FileType.FILE && 
compareonly.equals("only_files"))
-                  || (info.getFile().getType() == FileType.FOLDER
-                      && compareonly.equals("only_folders"))
-                  || (getFileWildcard(shortFilename) && 
compareonly.equals("specify"))
-                  || (compareonly.equals("all"))) {
-                returncode = true;
-              }
+
+            if ((includesubfolders
+                    && (info.getFile().getType() == FileType.FILE
+                        && compareonly.equals("only_files"))
+                || (info.getFile().getType() == FileType.FOLDER
+                    && compareonly.equals("only_folders"))
+                || (getFileWildcard(shortFilename) && 
compareonly.equals("specify"))
+                || (compareonly.equals("all")))) {
+              returncode = true;
             }
           }
         }

Reply via email to