hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1630919 - /hive/trunk/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HCatUtil.java
Date Fri, 10 Oct 2014 15:04:49 GMT
Author: gates
Date: Fri Oct 10 15:04:48 2014
New Revision: 1630919

URL: http://svn.apache.org/r1630919
Log:
HIVE-8347 Use base-64 encoding instead of custom encoding for serialized objects (Mariappan
Asokan via Alan Gates)

Modified:
    hive/trunk/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HCatUtil.java

Modified: hive/trunk/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HCatUtil.java
URL: http://svn.apache.org/viewvc/hive/trunk/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HCatUtil.java?rev=1630919&r1=1630918&r2=1630919&view=diff
==============================================================================
--- hive/trunk/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HCatUtil.java (original)
+++ hive/trunk/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HCatUtil.java Fri
Oct 10 15:04:48 2014
@@ -33,6 +33,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
+import org.apache.commons.codec.binary.Base64;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.conf.Configuration;
@@ -120,25 +121,11 @@ public class HCatUtil {
   }
 
   public static String encodeBytes(byte[] bytes) {
-    StringBuilder strBuf = new StringBuilder();
-
-    for (int i = 0; i < bytes.length; i++) {
-      strBuf.append((char) (((bytes[i] >> 4) & 0xF) + ('a')));
-      strBuf.append((char) (((bytes[i]) & 0xF) + ('a')));
-    }
-
-    return strBuf.toString();
+    return new String(Base64.encodeBase64(bytes, false, false));
   }
 
   public static byte[] decodeBytes(String str) {
-    byte[] bytes = new byte[str.length() / 2];
-    for (int i = 0; i < str.length(); i += 2) {
-      char c = str.charAt(i);
-      bytes[i / 2] = (byte) ((c - 'a') << 4);
-      c = str.charAt(i + 1);
-      bytes[i / 2] += (c - 'a');
-    }
-    return bytes;
+    return Base64.decodeBase64(str.getBytes());
   }
 
   public static List<HCatFieldSchema> getHCatFieldSchemaList(



Mime
View raw message