question: public static ByteArrayOutputStream encode ( String plaintext ) throws IOException , MessagingException { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; byte [ ] in = plaintext . getBytes ( ) ; ByteArrayOutputStream inStream = new ByteArrayOutputStream ( ) ; inStream . write ( in , 0 , in . length ) ; if ( ( in . length % 3 ) == 1 ) { inStream . write ( 0 ) ; inStream . write ( 0 ) ; } else if ( ( in . length % 3 ) == 2 ) { inStream . write ( 0 ) ; } inStream . writeTo ( MimeUtility . encode ( out , "base64" ) ) ; return out ; }
target:  Encode String to base64