Here you can find the source of encode(String str)
public static String encode(String str)
//package com.java2s; //License from project: Apache License import sun.misc.BASE64Encoder; import java.io.UnsupportedEncodingException; public class Main { public static String encode(String str) { byte[] b = null; String s = null;/*from w w w.j ava2 s . c o m*/ try { b = str.getBytes("utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } if (b != null) { s = new BASE64Encoder().encode(b); } return s; } }