private String encodeBytesFromBuffer ( int howMany ) { String result ; if ( innerStreamHasMoreData ) { howMany = howMany - howMany % 3 ; } if ( howMany == 0 ) { return "" ; } byte [ ] encodeBuffer = new byte [ howMany ] ; System . arraycopy ( buffer , 0 , encodeBuffer , 0 , howMany ) ; result = Base64 . encodeToString ( encodeBuffer ) ; bytesInBuffer -= howMany ; if ( bytesInBuffer != 0 ) { System . arraycopy ( buffer , howMany , buffer , 0 , bytesInBuffer ) ; } return result ; }
Encode a group of bytes and remove them from the buffer . If the input stream has more data we need to limit the encoding to a multiple of 3 to avoid prematurely padding the result with equals signs .