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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1b50b70  HIVE-22673: Replace Base64 in contrib Package (David 
Mollitor, reviewed by Zoltan Haindrich)
1b50b70 is described below

commit 1b50b7013f107418678f3241fea99d77d8606d7b
Author: David Mollitor <[email protected]>
AuthorDate: Fri Mar 6 12:12:30 2020 -0500

    HIVE-22673: Replace Base64 in contrib Package (David Mollitor, reviewed by 
Zoltan Haindrich)
---
 .../fileformat/base64/Base64TextInputFormat.java   | 31 ++--------------------
 .../fileformat/base64/Base64TextOutputFormat.java  |  5 ++--
 2 files changed, 4 insertions(+), 32 deletions(-)

diff --git 
a/contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextInputFormat.java
 
b/contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextInputFormat.java
index 9164aaa..dc812d4 100644
--- 
a/contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextInputFormat.java
+++ 
b/contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextInputFormat.java
@@ -20,11 +20,9 @@ package org.apache.hadoop.hive.contrib.fileformat.base64;
 
 import java.io.IOException;
 import java.util.Arrays;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
+import java.util.Base64;
 import java.nio.charset.StandardCharsets;
 
-import org.apache.commons.codec.binary.Base64;
 import org.apache.hadoop.io.BytesWritable;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.Text;
@@ -105,7 +103,7 @@ public class Base64TextInputFormat implements
         if (length != textBytes.length) {
           textBytes = Arrays.copyOf(textBytes, length);
         }
-        byte[] binaryData = base64.decode(textBytes);
+        byte[] binaryData = Base64.getDecoder().decode(textBytes);
 
         // compare data header with signature
         int i;
@@ -126,7 +124,6 @@ public class Base64TextInputFormat implements
     }
 
     private byte[] signature;
-    private final Base64 base64 = createBase64();
 
     @Override
     public void configure(JobConf job) {
@@ -167,28 +164,4 @@ public class Base64TextInputFormat implements
     return format.getSplits(job, numSplits);
   }
 
-  /**
-   * Workaround an incompatible change from commons-codec 1.3 to 1.4.
-   * Since Hadoop has this jar on its classpath, we have no way of knowing
-   * which version we are running against.
-   */
-  static Base64 createBase64() {
-    try {
-      // This constructor appeared in 1.4 and specifies that we do not want to
-      // line-wrap or use any newline separator
-      Constructor<Base64> ctor = Base64.class.getConstructor(int.class, 
byte[].class);
-      return ctor.newInstance(0, null);
-    } catch (NoSuchMethodException e) { // ie we are running 1.3
-      // In 1.3, this constructor has the same behavior, but in 1.4 the default
-      // was changed to add wrapping and newlines.
-      return new Base64();
-    } catch (InstantiationException e) {
-      throw new RuntimeException(e);
-    } catch (IllegalAccessException e) {
-      throw new RuntimeException(e);
-    } catch (InvocationTargetException e) {
-      throw new RuntimeException(e.getCause());
-    }
-  }
-
 }
diff --git 
a/contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextOutputFormat.java
 
b/contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextOutputFormat.java
index 35c1e68..f99a6ae 100644
--- 
a/contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextOutputFormat.java
+++ 
b/contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextOutputFormat.java
@@ -20,9 +20,9 @@ package org.apache.hadoop.hive.contrib.fileformat.base64;
 
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
+import java.util.Base64;
 import java.util.Properties;
 
-import org.apache.commons.codec.binary.Base64;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hive.ql.exec.FileSinkOperator.RecordWriter;
 import org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat;
@@ -89,7 +89,7 @@ public class Base64TextOutputFormat<K extends 
WritableComparable, V extends Writ
       }
 
       // Encode
-      byte[] output = base64.encode(wrapped);
+      byte[] output = Base64.getEncoder().encode(wrapped);
       bytesWritable.set(output, 0, output.length);
 
       writer.write(bytesWritable);
@@ -101,7 +101,6 @@ public class Base64TextOutputFormat<K extends 
WritableComparable, V extends Writ
     }
 
     private byte[] signature;
-    private final Base64 base64 = Base64TextInputFormat.createBase64();
 
     @Override
     public void configure(JobConf job) {

Reply via email to