Here you can find the source of encode(byte[] b)
public static byte[] encode(byte[] b) throws MessagingException, IOException
//package com.java2s; //License from project: Apache License import javax.mail.MessagingException; import javax.mail.internet.MimeUtility; import java.io.*; public class Main { public static byte[] encode(byte[] b) throws MessagingException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream b64os = MimeUtility.encode(baos, "base64"); b64os.write(b);//w ww .j ava 2 s . c om b64os.close(); return baos.toByteArray(); } }