public ByteBuffer encode (final CodePointBuffer text, ByteBuffer buffer)
{
final int textLength = text.getLength();
if (buffer == null)
{
buffer = new ByteBuffer(textLength * 2);
}
else if ((buffer.getLength() * 2) < textLength)
{
buffer.ensureSize(textLength * 2);
}