question: public final ByteBuffer encode ( CharBuffer in ) throws CharacterCodingException { int length = ( int ) ( in . remaining ( ) * averageBytesPerChar ) ; ByteBuffer out = ByteBuffer . allocate ( length ) ; reset ( ) ; while ( state != FLUSHED ) { CoderResult result = encode ( in , out , true ) ; if ( result == CoderResult . OVERFLOW ) { out = allocateMore ( out ) ; continue ; } else { checkCoderResult ( result ) ; } result = flush ( out ) ; if ( result == CoderResult . OVERFLOW ) { out = allocateMore ( out ) ; } else { checkCoderResult ( result ) ; } } out . flip ( ) ; return out ; }
target:  This is a facade method for the encoding operation. <p> This method encodes the remaining character sequence of the given character buffer into a new byte buffer. This method performs a complete encoding operation, resets at first, then encodes, and flushes at last. <p> This method should not be invoked if another encode operation is ongoing.