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;
}

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 ; }
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 .
