public static String encode(byte [] bytes){
        int length = bytes.length;
        int start = 0;

        byte[] dst = new byte[(length+2)/3 * 4 + length/72];
        int x = 0;
        int dstIndex = 0;
        int state = 0;	// which char in pattern
        int old = 0;	// previous byte
        int len = 0;	// length decoded so far
        int max = length + start;
        for (int srcIndex = start; srcIndex<max; srcIndex++) {
            x = bytes[srcIndex];
            switch (++state) {
                case 1:
                    dst[dstIndex++] = base64bytes[(x>>2) & 0x3f];
                    break;
                case 2:
                    dst[dstIndex++] = base64bytes[((old<<4)&0x30)
                            | ((x>>4)&0xf)];
                    break;
                case 3:
                    dst[dstIndex++] = base64bytes[((old<<2)&0x3C)
                            | ((x>>6)&0x3)];
                    dst[dstIndex++] = base64bytes[x&0x3F];
                    state = 0;
                    break;
            }
            old = x;
            if (++len >= 72) {
                dst[dstIndex++] = (byte) '\n';
                len = 0;
            }
        }

	/*
	 * now clean up the end bytes
	 */

        switch (state) {
            case 1: dst[dstIndex++] = base64bytes[(old<<4) & 0x30];
                dst[dstIndex++] = (byte) '=';
                dst[dstIndex++] = (byte) '=';
                break;
            case 2: dst[dstIndex++] = base64bytes[(old<<2) & 0x3c];
                dst[dstIndex++] = (byte) '=';
                break;
        }
        return new String(dst);
    }
public static String encode ( byte [ ] bytes ) { int length = bytes . length ; int start = 0 ; byte [ ] dst = new byte [ ( length + 2 ) / 3 * 4 + length / 72 ] ; int x = 0 ; int dstIndex = 0 ; int state = 0 ; int old = 0 ; int len = 0 ; int max = length + start ; for ( int srcIndex = start ; srcIndex < max ; srcIndex ++ ) { x = bytes [ srcIndex ] ; switch ( ++ state ) { case 1 : dst [ dstIndex ++ ] = base64bytes [ ( x > > 2 ) & 0x3f ] ; break ; case 2 : dst [ dstIndex ++ ] = base64bytes [ ( ( old << 4 ) & 0x30 ) | ( ( x > > 4 ) & 0xf ) ] ; break ; case 3 : dst [ dstIndex ++ ] = base64bytes [ ( ( old << 2 ) & 0x3C ) | ( ( x > > 6 ) & 0x3 ) ] ; dst [ dstIndex ++ ] = base64bytes [ x & 0x3F ] ; state = 0 ; break ; } old = x ; if ( ++ len >= 72 ) { dst [ dstIndex ++ ] = ( byte ) '\n' ; len = 0 ; } } switch ( state ) { case 1 : dst [ dstIndex ++ ] = base64bytes [ ( old << 4 ) & 0x30 ] ; dst [ dstIndex ++ ] = ( byte ) '=' ; dst [ dstIndex ++ ] = ( byte ) '=' ; break ; case 2 : dst [ dstIndex ++ ] = base64bytes [ ( old << 2 ) & 0x3c ] ; dst [ dstIndex ++ ] = ( byte ) '=' ; break ; } return new String ( dst ) ; }
@param bytes
@return