UnsyncCharArrayWriter extends Writer { public CharBuffer toCharBuffer() { return CharBuffer.wrap(_buffer, 0, _index); } UnsyncCharArrayWriter();  UnsyncCharArrayWriter(int initialSize); @Override Writer append(char c); @Override Writer append(CharSequence charSequence); @Override Writer append(CharSequence charSequence, int start, int end); @Override void close(); @Override void flush(); void reset(); int size(); CharBuffer toCharBuffer(); @Override String toString(); @Override void write(char[] chars); @Override void write(char[] chars, int offset, int length); @Override void write(int c); @Override void write(String string); @Override void write(String string, int offset, int length); int writeTo(CharBuffer charBuffer); int writeTo(OutputStream outputStream, String charsetName); int writeTo(Writer writer);  }
@Test public void testToCharBuffer() throws Exception { UnsyncCharArrayWriter unsyncCharArrayWriter = new UnsyncCharArrayWriter(); char[] buffer = (char[])_bufferField.get(unsyncCharArrayWriter); unsyncCharArrayWriter.write("test1"); CharBuffer charBuffer = unsyncCharArrayWriter.toCharBuffer(); Assert.assertSame(buffer, charBuffer.array()); Assert.assertEquals(0, charBuffer.position()); Assert.assertEquals(5, charBuffer.limit()); Assert.assertEquals("test1", charBuffer.toString()); }