public final ByteBuffer encode(CharBuffer in) throws CharacterCodingException {if (in.remaining() == 0) {return ByteBuffer.allocate(0);}reset();int length = (int) (in.remaining() * averageBytesPerChar);ByteBuffer output = ByteBuffer.allocate(length);CoderResult result = null;while (true) {result = encode(in, output, false);if (result==CoderResult.UNDERFLOW) {break;} else if (result==CoderResult.OVERFLOW) {output = allocateMore(output);continue;}checkCoderResult(result);}result = encode(in, output, true);checkCoderResult(result);while (true) {result = flush(output);if (result==CoderResult.UNDERFLOW) {output.flip();break;} else if (result==CoderResult.OVERFLOW) {output = allocateMore(output);continue;}checkCoderResult(result);output.flip();if (result.isMalformed()) {throw new MalformedInputException(result.length());} else if (result.isUnmappable()) {throw new UnmappableCharacterException(result.length());}break;}status = READY;finished = true;return output;}

public java.nio.ByteBuffer encode(java.nio.CharBuffer @in){if (@in.remaining() == 0){return java.nio.ByteBuffer.allocate(0);}reset();int length = (int)(@in.remaining() * _averageBytesPerChar);java.nio.ByteBuffer output = java.nio.ByteBuffer.allocate(length);java.nio.charset.CoderResult result = null;while (true){result = encode(@in, output, false);if (result == java.nio.charset.CoderResult.UNDERFLOW){break;}else{if (result == java.nio.charset.CoderResult.OVERFLOW){output = allocateMore(output);continue;}}checkCoderResult(result);}result = encode(@in, output, true);checkCoderResult(result);while (true){result = flush(output);if (result == java.nio.charset.CoderResult.UNDERFLOW){output.flip();break;}else{if (result == java.nio.charset.CoderResult.OVERFLOW){output = allocateMore(output);continue;}}checkCoderResult(result);output.flip();if (result.isMalformed()){throw new java.nio.charset.MalformedInputException(result.length());}else{if (result.isUnmappable()){throw new java.nio.charset.UnmappableCharacterException(result.length());}}break;}status = READY;finished = true;return output;}
