### Question:
IOUtils { @VisibleForAdvice public static boolean readUtf8Stream(final InputStream is, final CharBuffer charBuffer) throws IOException { final ByteBuffer buffer = threadLocalByteBuffer.get(); final CharsetDecoder charsetDecoder = threadLocalCharsetDecoder.get(); try { final byte[] bufferArray = buffer.array(); for (int read = is.read(bufferArray); read != -1; read = is.read(bufferArray)) { ((Buffer) buffer).limit(read); final CoderResult coderResult = charsetDecoder.decode(buffer, charBuffer, true); ((Buffer) buffer).clear(); if (coderResult.isError()) { ((Buffer) charBuffer).clear(); return false; } else if (coderResult.isOverflow()) { break; } } charsetDecoder.flush(charBuffer); return true; } finally { ((Buffer) charBuffer).flip(); ((Buffer) buffer).clear(); charsetDecoder.reset(); is.close(); } }  @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 readUtf8Stream() throws IOException { final CharBuffer charBuffer = CharBuffer.allocate(8); assertThat(IOUtils.readUtf8Stream(toInputStream("{foo}", UTF_8), charBuffer)).isTrue(); assertThat(charBuffer.toString()).isEqualTo("{foo}"); }
@Test void testStreamLargerThanByteBuffer() throws IOException { final CharBuffer charBuffer = CharBuffer.allocate(IOUtils.BYTE_BUFFER_CAPACITY * 2); final String longString = RandomStringUtils.randomAlphanumeric(IOUtils.BYTE_BUFFER_CAPACITY * 2); assertThat(IOUtils.readUtf8Stream(toInputStream(longString, UTF_8), charBuffer)).isTrue(); assertThat(charBuffer.toString()).isEqualTo(longString); }
@Test void testReusedBuffer() throws IOException { final QueueBasedObjectPool<CharBuffer> charBuffers = QueueBasedObjectPool.of(new ArrayBlockingQueue<>(1), true, () -> CharBuffer.allocate(8), CharBuffer::clear); final CharBuffer charBuffer1 = charBuffers.createInstance(); assertThat(IOUtils.readUtf8Stream(toInputStream("foo", UTF_8), charBuffer1)).isTrue(); assertThat(charBuffer1.toString()).isEqualTo("foo"); charBuffers.recycle(charBuffer1); final CharBuffer charBuffer2 = charBuffers.createInstance(); assertThat(IOUtils.readUtf8Stream(toInputStream("barbaz", UTF_8), charBuffer2)).isTrue(); assertThat(charBuffer2.toString()).isEqualTo("barbaz"); assertThat((Object) charBuffer1).isSameAs(charBuffer2); }
@Test void testOverflowStream() throws IOException { final CharBuffer charBuffer = CharBuffer.allocate(8); assertThat(IOUtils.readUtf8Stream(toInputStream("foobarbaz", UTF_8), charBuffer)).isTrue(); assertThat(charBuffer.toString()).isEqualTo("foobarba"); }
@Test void readUtf16Stream() throws IOException { final CharBuffer charBuffer = CharBuffer.allocate(16); assertThat(IOUtils.readUtf8Stream(toInputStream("{foo}", UTF_16), charBuffer)).isFalse(); assertThat(charBuffer.length()).isZero(); }