drools-eclipse/org.guvnor.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/Base64Encoder.java
public static String encode(byte[] data) {
        Assert.isNotNull(data);

        StringBuffer buf = new StringBuffer();

        byte b = 0;
        int bits = 2;

        for (int i = 0; i < data.length; ++i) {
            b = (byte) ((b | (data[i] >> bits)) & 0x003f);
            buf.append(encode(b));
            b = (byte) ((data[i] << 6 - bits) & 0x003f);
            bits += 2;
            if (bits == 8) {
                buf.append(encode((byte) (b & 0x003f)));
                b = 0;
                bits = 2;
            }
        }

        if (bits == 4) {
            buf.append(encode(b));
            buf.append("=="); //$NON-NLS-1$
        } else if (bits == 6) {
            buf.append(encode(b));
            buf.append('=');
        }

        return buf.toString();
    }
public static String encode(byte[] data) {
        Assert.isNotNull(data);

        StringBuffer buf = new StringBuffer();

        byte b = 0;
        int bits = 2;

        for (int i = 0; i < data.length; ++i) {
            b = (byte) ((b | (data[i] >> bits)) & 0x003f);
            buf.append(encode(b));
            b = (byte) ((data[i] << 6 - bits) & 0x003f);
            bits += 2;
            if (bits == 8) {
                buf.append(encode((byte) (b & 0x003f)));
                b = 0;
                bits = 2;
            }
        }

        if (bits == 4) {
            buf.append(encode(b));
            buf.append("=="); //$NON-NLS-1$
        } else if (bits == 6) {
            buf.append(encode(b));
            buf.append('=');
        }

        return buf.toString();
    }
public static String encode ( byte [ ] data ) { Assert . isNotNull ( data ) ; StringBuffer buf = new StringBuffer ( ) ; byte b = 0 ; int bits = 2 ; for ( int i = 0 ; i < data . length ; ++ i ) { b = ( byte ) ( ( b | ( data [ i ] >> bits ) ) & 0x003f ) ; buf . append ( encode ( b ) ) ; b = ( byte ) ( ( data [ i ] << 6 - bits ) & 0x003f ) ; bits += 2 ; if ( bits == 8 ) { buf . append ( encode ( ( byte ) ( b & 0x003f ) ) ) ; b = 0 ; bits = 2 ; } } if ( bits == 4 ) { buf . append ( encode ( b ) ) ; buf . append ( "==" ) ; //$NON-NLS-1$ } else if ( bits == 6 ) { buf . append ( encode ( b ) ) ; buf . append ( ' ' ) ; } return buf . toString ( ) ; }
Returns the BASE64 encoded <code>String</code> of the given data.

@param data the bytes to be BASE64 encoded
@return     the BASE64 encoded <code>String</code> of the given data
Returns the BASE64 encoded <code > String< / code > of the given data .