public final ByteBuffer encode (CharBuffer in) throws CharacterCodingException

Convenience method that encodes the remaining content of a single input character buffer into a newly-allocated byte buffer.

This method implements an entire encoding operation; that is, it resets this encoder, then it encodes the characters in the given character buffer, and finally it flushes this encoder. This method should therefore not be invoked if an encoding operation is already in progress.

Parameters:
in     The input character buffer

Returns:  A newly-allocated byte buffer containing the result of the encoding operation. The buffer's position will be zero and its limit will follow the last byte written.

Exceptions:
IllegalStateException     If an encoding operation is already in progress
MalformedInputException     If the character sequence starting at the input buffer's current position is not a legal sixteen-bit Unicode sequence and the current malformed-input action is CodingErrorAction.REPORT
UnmappableCharacterException     If the character sequence starting at the input buffer's current position cannot be mapped to an equivalent byte sequence and the current unmappable-character action is CodingErrorAction.REPORT