// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.mail.MessagingException;
import javax.mail.internet.MimeUtility;

public class B64Check {
    public static String b64encode(byte[] b) throws MessagingException, IOException  {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OutputStream b64os = MimeUtility.encode(baos, "base64");
        b64os.write(b);
        b64os.close();
        return (new String(baos.toByteArray())).replace("\r\n", "");
     }
    public static void main(String[] args) throws Exception {
        for(int i = 0; i < 100; i++) {
            byte[] b = new byte[i];
            String s = b64encode(b);
            if(s.length() % 4 != 0) {
                System.out.println("Problem with length " + i + " becoming " + s.length());
            }
        }
    }
}
