private static char [ ] encodeGroup ( byte [ ] data , int position ) { final char [ ] c = new char [ ] { ' ' , ' ' , ' ' , ' ' } ; int b1 = 0 , b2 = 0 , b3 = 0 ; int length = data . length - position ; if ( length == 0 ) return c ; if ( length >= 1 ) { b1 = ( data [ position ] ) & 0xFF ; } if ( length >= 2 ) { b2 = ( data [ position + 1 ] ) & 0xFF ; } if ( length >= 3 ) { b3 = ( data [ position + 2 ] ) & 0xFF ; } c [ 0 ] = ALPHABET [ b1 >> 2 ] ; c [ 1 ] = ALPHABET [ ( b1 & 3 ) << 4 | ( b2 >> 4 ) ] ; if ( length == 1 ) return c ; c [ 2 ] = ALPHABET [ ( b2 & 15 ) << 2 | ( b3 >> 6 ) ] ; if ( length == 2 ) return c ; c [ 3 ] = ALPHABET [ b3 & 0x3f ] ; return c ; }
Encode three bytes of data into four characters .