Here you can find the source of encodeBase64(String s, Charset cs)
public static String encodeBase64(String s, Charset cs)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.nio.charset.Charset; import javax.mail.MessagingException; import javax.mail.internet.MimeUtility; public class Main { public static String encodeBase64(String s, Charset cs) { String out = null;//from w ww .j a v a 2 s . c o m ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { OutputStream os = MimeUtility.encode(baos, "BASE64"); os.write(s.getBytes(cs)); out = new String(baos.toByteArray(), cs); } catch (IOException ignore) { ; } catch (MessagingException ignore) { ; } finally { if (baos != null) { try { baos.close(); } catch (IOException ignore) { ; } } } return out; } }