### Question:
ByteVector { public ByteVector putUTF8(final String stringValue) { int charLength = stringValue.length(); if (charLength > 65535) { throw new IllegalArgumentException("UTF8 string too large"); } int currentLength = length; if (currentLength + 2 + charLength > data.length) { enlarge(2 + charLength); } byte[] currentData = data; currentData[currentLength++] = (byte) (charLength >>> 8); currentData[currentLength++] = (byte) charLength; for (int i = 0; i < charLength; ++i) { char charValue = stringValue.charAt(i); if (charValue >= '\u0001' && charValue <= '\u007F') { currentData[currentLength++] = (byte) charValue; } else { length = currentLength; return encodeUtf8(stringValue, i, 65535); } } length = currentLength; return this; } ByteVector();  ByteVector(final int initialCapacity);   ByteVector(final byte[] data); ByteVector putByte(final int byteValue); ByteVector putShort(final int shortValue); ByteVector putInt(final int intValue); ByteVector putLong(final long longValue); ByteVector putUTF8(final String stringValue); ByteVector putByteArray(
      final byte[] byteArrayValue, final int byteOffset, final int byteLength);  }### Answer:
@Test public void testPutUtf8_ascii() { ByteVector byteVector = new ByteVector(0); byteVector.putUTF8("abc"); assertArrayEquals(new byte[] {0, 3, 'a', 'b', 'c'}, toArray(byteVector)); }
@Test public void testPutUtf8_unicode() { ByteVector byteVector = new ByteVector(0); byteVector.putUTF8(new String(new char[] {'a', 0x0000, 0x0080, 0x0800})); assertArrayEquals( new byte[] {0, 8, 'a', -64, -128, -62, -128, -32, -96, -128}, toArray(byteVector)); }
@Test public void testPutUtf8_unicode_tooLarge() { ByteVector byteVector = new ByteVector(0); char[] charBuffer = new char[32768]; Arrays.fill(charBuffer, (char) 0x07FF); Executable putUtf8 = () -> byteVector.putUTF8(new String(charBuffer)); Exception exception = assertThrows(IllegalArgumentException.class, putUtf8); assertEquals("UTF8 string too large", exception.getMessage()); }