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 cccb19a..5909188 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.commons.codec.binary.Base64; import org.apache.hadoop.hive.shims.ShimLoader; @@ -125,7 +127,7 @@ public class Base64TextInputFormat implements } private byte[] signature; - private final Base64 base64 = new Base64(); + private final Base64 base64 = createBase64(); @Override public void configure(JobConf job) { @@ -140,6 +142,7 @@ public class Base64TextInputFormat implements e.printStackTrace(); } } + } TextInputFormat format; @@ -174,4 +177,28 @@ public class Base64TextInputFormat implements 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 be77009..c9eb367 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 @@ -101,7 +101,7 @@ public class Base64TextOutputFormat