You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hop.apache.org by ha...@apache.org on 2023/03/29 10:42:26 UTC

[hop] branch master updated: Enable binary encode/decode in Calculator

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

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


The following commit(s) were added to refs/heads/master by this push:
     new f02604ecaa Enable binary encode/decode in Calculator
     new cdd86d5b3b Merge pull request #2778 from enricomariam42/master
f02604ecaa is described below

commit f02604ecaa77c526e30216af743bc99e47105a4a
Author: enricomariam42 <en...@asst-brianza.it>
AuthorDate: Fri Mar 24 12:49:58 2023 +0100

    Enable binary encode/decode in Calculator
---
 .../pipeline/transforms/calculator/Calculator.java   | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/plugins/transforms/calculator/src/main/java/org/apache/hop/pipeline/transforms/calculator/Calculator.java b/plugins/transforms/calculator/src/main/java/org/apache/hop/pipeline/transforms/calculator/Calculator.java
index 4c50635d1d..9e309c769a 100644
--- a/plugins/transforms/calculator/src/main/java/org/apache/hop/pipeline/transforms/calculator/Calculator.java
+++ b/plugins/transforms/calculator/src/main/java/org/apache/hop/pipeline/transforms/calculator/Calculator.java
@@ -618,18 +618,26 @@ public class Calculator extends BaseTransform<CalculatorMeta, CalculatorData> {
             break;
           case BASE64_ENCODE:
             if(dataA != null){
-              calcData[index] = Base64.getEncoder().withoutPadding().encodeToString(dataA.toString().getBytes());
-            }else{
+              if(metaA.getType() == IValueMeta.TYPE_BINARY) {
+                calcData[index] = Base64.getEncoder().withoutPadding().encodeToString(metaA.getBinary(dataA));
+              } else {
+                calcData[index] = Base64.getEncoder().withoutPadding().encodeToString(metaA.getString(dataA).getBytes());
+              }
+            } else {
               calcData[index] = null;
             }
             resultType = IValueMeta.TYPE_STRING;
             break;
           case BASE64_DECODE:
             if(dataA != null){
-              byte[] tmpDecoded = Base64.getDecoder().decode(dataA.toString());
-              String tmpDecodedString = new String(tmpDecoded);
-              calcData[index] = targetMeta.convertData(metaA, tmpDecodedString);
-            }else{
+              byte[] tmpDecoded = Base64.getDecoder().decode(metaA.getString(dataA));
+              if(targetMeta.getType() == IValueMeta.TYPE_BINARY) {
+                calcData[index] = tmpDecoded;
+              } else {
+                String tmpDecodedString = new String(tmpDecoded);
+                calcData[index] = targetMeta.convertData(metaA, tmpDecodedString);  
+              }
+            } else {
               calcData[index] = null;
             }
             resultType = targetMeta.getType();