Coverage Report - datafu.pig.hash.MD5Base64
 
Classes in this File Line Coverage Branch Coverage Complexity
MD5Base64
71%
5/7
N/A
2
 
 1  
 /*
 2  
  * Copyright 2010 LinkedIn, Inc
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 5  
  * use this file except in compliance with the License. You may obtain a copy of
 6  
  * the License at
 7  
  * 
 8  
  * http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 12  
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 13  
  * License for the specific language governing permissions and limitations under
 14  
  * the License.
 15  
  */
 16  
  
 17  
 package datafu.pig.hash;
 18  
 
 19  
 import java.security.MessageDigest;
 20  
 import java.security.NoSuchAlgorithmException;
 21  
 
 22  
 import org.apache.commons.codec.binary.Base64;
 23  
 
 24  
 import datafu.pig.util.SimpleEvalFunc;
 25  
 
 26  
 /**
 27  
  * Computes the MD5 value of a string and outputs it in Base64 encoding.
 28  
  */
 29  
 public class MD5Base64 extends SimpleEvalFunc<String>
 30  
 {
 31  
     private final MessageDigest md5er;
 32  
 
 33  
     public MD5Base64()
 34  717
     {
 35  
         try {
 36  717
             md5er = MessageDigest.getInstance("md5");
 37  
         }
 38  0
         catch (NoSuchAlgorithmException e) {
 39  0
             throw new RuntimeException(e);
 40  717
         }
 41  717
     }
 42  
 
 43  
     public String call(String val)
 44  
     {
 45  3
         return new String(Base64.encodeBase64(md5er.digest(val.getBytes())));
 46  
     }
 47  
 }