1 16 17 18 package org.apache.xmlrpc.util; 19 20 import org.apache.commons.codec.binary.Base64; 21 import org.apache.commons.codec.EncoderException; 22 23 28 public class HttpUtil 29 { 30 private static final Base64 base64; 31 32 static { 33 base64 = new Base64(); 34 } 35 36 private HttpUtil() 37 { 38 } 40 41 public static String encodeBasicAuthentication(String user, String password) 42 { 43 String auth; 44 if (user == null || password == null) 45 { 46 auth = null; 47 } 48 else 49 { 50 try 51 { 52 Object bytes = (user + ':' + password).getBytes(); 53 auth = new String ((byte[]) base64.encode(bytes)).trim(); 54 } 55 catch (EncoderException e) 56 { 57 throw new RuntimeException ("Possibly incompatible version of '" 60 + Base64.class.getName() + 61 "' used: " + e); 62 } 63 } 64 return auth; 65 } 66 } 67 | Popular Tags |