org.apache.commons.codec.binary.Base64与sun.misc.BASE64Encoder等效

Spark SQL自定义函数遇见这个问题


	import org.apache.commons.codec.binary.Base64;
	
	private static void test1() throws Exception {
		// encode
		String toBeEncode = "123";
		
		sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
		String result = encoder.encode(toBeEncode.getBytes("UTF-8"));
		System.out.println(result);
		
		System.out.println("----");
		
		byte[] encodeBase64 = Base64.encodeBase64(toBeEncode.getBytes("UTF-8"));
		System.out.println(new String(encodeBase64));
		
		System.out.println("####");
		
		// decode
		String toBeDecode = "MTIz";

		sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
		byte[] decodeResult = decoder.decodeBuffer(toBeDecode);
		System.out.println(new String(decodeResult, "UTF-8"));		
		
		System.out.println("----");
		
		byte[] decodeResult2 = Base64.decodeBase64(toBeDecode);
	    System.out.println(new String(decodeResult2, "UTF-8"));		
	}




你可能感兴趣的:(Java)