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 9164aaa37e..dc812d401b 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 @@ 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 boolean next(LongWritable key, BytesWritable value) throws IOException { 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 boolean next(LongWritable key, BytesWritable value) throws IOException { } private byte[] signature; - private final Base64 base64 = createBase64(); @Override public void configure(JobConf job) { @@ -167,28 +164,4 @@ public void configure(JobConf job) { 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 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 35c1e6855c..f99a6aeaa2 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 @@ 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 void write(Writable w) throws IOException { } // 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 void close(boolean abort) throws IOException { } private byte[] signature; - private final Base64 base64 = Base64TextInputFormat.createBase64(); @Override public void configure(JobConf job) {