@Test
    public void testByteBufferEncoding() {
        for (int c : TEST_CODEPOINTS) {
            ByteBuffer buffer = ByteBuffer.allocate(4);
            Utf8.encode(c, buffer);
            byte[] encoded = new byte[buffer.position()];
            buffer.flip();
            for (int i = 0; i < encoded.length; ++i) {
                encoded[i] = buffer.get();
            }
            String testCharacter = makeString(c);
            byte[] utf8 = Utf8.toBytes(testCharacter);
            assertArrayEquals(utf8, encoded);
        }
        byte[] stringAsUtf8 = Utf8.toBytes(TEST_STRING);
        ByteBuffer buffer = ByteBuffer.allocate(TEST_STRING.length() * 4);
        for (int i = 0; i < TEST_STRING.length(); i = TEST_STRING.offsetByCodePoints(i, 1)) {
            Utf8.encode(TEST_STRING.codePointAt(i), buffer);
        }
        byte[] handEncoded = new byte[buffer.position()];
        buffer.flip();
        for (int i = 0; i < handEncoded.length; ++i) {
            handEncoded[i] = buffer.get();
        }
        assertArrayEquals(stringAsUtf8, handEncoded);
    }
@author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a>
@author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
vespajlib/src/test/java/com/yahoo/text/Utf8TestCase.java