public static String encode ( byte [ ] from ) { StringBuilder to = new StringBuilder ( ( int ) ( from . length * 1.34 ) + 3 ) ; int num = 0 ; char currentByte = 0 ; for ( int i = 0 ; i < from . length ; i ++ ) { num = num % 8 ; while ( num < 8 ) { switch ( num ) { case 0 : currentByte = ( char ) ( from [ i ] & lead6byte ) ; currentByte = ( char ) ( currentByte >>> 2 ) ; break ; case 2 : currentByte = ( char ) ( from [ i ] & last6byte ) ; break ; case 4 : currentByte = ( char ) ( from [ i ] & last4byte ) ; currentByte = ( char ) ( currentByte << 2 ) ; if ( ( i + 1 ) < from . length ) { currentByte |= ( from [ i + 1 ] & lead2byte ) >>> 6 ; } break ; case 6 : currentByte = ( char ) ( from [ i ] & last2byte ) ; currentByte = ( char ) ( currentByte << 4 ) ; if ( ( i + 1 ) < from . length ) { currentByte |= ( from [ i + 1 ] & lead4byte ) >>> 4 ; } break ; default : break ; } to . append ( encodeTable [ currentByte ] ) ; num += 6 ; } } if ( to . length ( ) % 4 != 0 ) { for ( int i = 4 - to . length ( ) % 4 ; i > 0 ; i -- ) { to . append ( "=" ) ; } } return to . toString ( ) ; }
Base64 encoding .