### Question:
IOUtils { @VisibleForAdvice public static CoderResult decodeUtf8Bytes(final byte[] bytes, final CharBuffer charBuffer) { return decodeUtf8Bytes(bytes, 0, bytes.length, charBuffer); }  @VisibleForAdvice static boolean readUtf8Stream(final InputStream is, final CharBuffer charBuffer); @VisibleForAdvice static CoderResult decodeUtf8Bytes(final byte[] bytes, final CharBuffer charBuffer); @VisibleForAdvice static CoderResult decodeUtf8Bytes(final byte[] bytes, final int offset, final int length, final CharBuffer charBuffer); @VisibleForAdvice static CoderResult decodeUtf8Byte(final byte b, final CharBuffer charBuffer); static synchronized File exportResourceToDirectory(String resource, String parentDirectory, String tempFileNamePrefix,
                                                              String tempFileNameExtension); static String md5Hash(InputStream resourceAsStream);  }### Answer:
@Test void readUtf8Bytes() { final CharBuffer charBuffer = CharBuffer.allocate(8); assertThat(IOUtils.decodeUtf8Bytes("{f".getBytes(UTF_8), charBuffer).isError()).isFalse(); assertThat(IOUtils.decodeUtf8Bytes("oo}".getBytes(UTF_8), charBuffer).isError()).isFalse(); charBuffer.flip(); assertThat(charBuffer.toString()).isEqualTo("{foo}"); }
@Test void readUtf8BytesOffsetLength() { final CharBuffer charBuffer = CharBuffer.allocate(8); final byte[] bytes = "{foo}".getBytes(UTF_8); final byte[] buffer = new byte[512]; System.arraycopy(bytes, 0, buffer, 42, bytes.length); assertThat(IOUtils.decodeUtf8Bytes(buffer, 42, bytes.length, charBuffer).isError()).isFalse(); charBuffer.flip(); assertThat(charBuffer.toString()).isEqualTo("{foo}"); }
@Test void testBytesLargerThanByteBuffer() { final CharBuffer charBuffer = CharBuffer.allocate(IOUtils.BYTE_BUFFER_CAPACITY * 2); final String longString = RandomStringUtils.randomAlphanumeric(IOUtils.BYTE_BUFFER_CAPACITY * 2); assertThat(IOUtils.decodeUtf8Bytes(longString.getBytes(UTF_8), charBuffer).isError()).isFalse(); charBuffer.flip(); assertThat(charBuffer.toString()).isEqualTo(longString); }
@Test void testOverflowBytes() { final CharBuffer charBuffer = CharBuffer.allocate(8); assertThat(IOUtils.decodeUtf8Bytes("foobarbaz".getBytes(UTF_8), charBuffer).isOverflow()).isTrue(); assertThat(IOUtils.decodeUtf8Bytes("qux".getBytes(UTF_8), charBuffer).isOverflow()).isTrue(); charBuffer.flip(); assertThat(charBuffer.toString()).isEqualTo("foobarba"); }
@Test void readUtf16Bytes() { final CharBuffer charBuffer = CharBuffer.allocate(16); assertThat(IOUtils.decodeUtf8Bytes("{foo}".getBytes(UTF_16), charBuffer).isError()).isTrue(); assertThat((CharSequence) charBuffer).isEqualTo(CharBuffer.allocate(16)); }