Here you can find the source of encodeBase64(String str)
public static String encodeBase64(String str) throws Exception
//package com.java2s; /**// ww w.j av a2s. c o m * ETRI Distributed Resource/Mediation System for new re-generation Energy Exchange * * Copyright ? [2016] ETRI. All rights reserved. * * This is a proprietary software of ETRI, and you may not use this file except in * compliance with license agreement with ETRI. Any redistribution or use of this * software, with or without modification shall be strictly prohibited without prior written * approval of ETRI, and the copyright notice above does not evidence any actual or * intended publication of such software. * * com.nc.common.utils : StringUtil.java * @author creme55 * @since 2016. 10. 12. * @version 1.0 * @see * @Copyright ? [2016] By ETRI. All rights reserved. * * <pre> * << ??????(Modification Information) >> * ????? ???? ???? * ------------- ----------- ------------------------- * 2016. 10. 12. creme55 ?? ???(???? ?? ????) * * </pre> **/ import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import javax.mail.internet.MimeUtility; public class Main { public static String encodeBase64(String str) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream b64os = MimeUtility.encode(baos, "base64"); b64os.write(str.getBytes()); b64os.close(); return baos.toString().trim(); } public static String encode(String str, String enc) { if (str != null) { try { str = URLEncoder.encode(str, enc); } catch (UnsupportedEncodingException ex) { return str; } } return str; } public static String trim(String str) { return (str == null ? null : str.trim()); } public static String toString(int value) { return Integer.toString(value); } }