commit 72a2fafa6b38d3385f1519a9fc613d5a1402e4e4 Author: Todd Lipcon Date: Fri Sep 10 11:49:00 2010 -0700 HIVE-1628. Fix Base64TextInputFormat to be compatible with commons codec 1.4 Reason: Hadoop now ships commons-codec 1.4, so it ends up on Hive's classpath Author: Todd Lipcon diff --git contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextInputFormat.java contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextInputFormat.java index e3a1fe8..39d31a6 100644 --- contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextInputFormat.java +++ contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextInputFormat.java @@ -21,6 +21,8 @@ package org.apache.hadoop.hive.contrib.fileformat.base64; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.Arrays; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import org.apache.hadoop.hive.shims.ShimLoader; import org.apache.hadoop.io.BytesWritable; @@ -122,7 +124,7 @@ public class Base64TextInputFormat } private byte[] signature; - private Base64 base64 = new Base64(); + private Base64 base64 = createBase64(); @Override public void configure(JobConf job) { @@ -137,6 +139,7 @@ public class Base64TextInputFormat e.printStackTrace(); } } + } TextInputFormat format; @@ -172,4 +175,28 @@ public class Base64TextInputFormat ShimLoader.getHadoopShims().inputFormatValidateInput(format, job); } + /** + * 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 contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextOutputFormat.java contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextOutputFormat.java index 81b5743..bbe915b 100644 --- contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextOutputFormat.java +++ contrib/src/java/org/apache/hadoop/hive/contrib/fileformat/base64/Base64TextOutputFormat.java @@ -99,7 +99,7 @@ public class Base64TextOutputFormat