UnsafeByteArrayOutputStream extends Output implements ExtendedDataOutput { @Override public void writeChars(String s) throws IOException { int len = s.length(); require(len * SIZE_OF_CHAR); for (int i = 0; i < len; i++) { int v = s.charAt(i); writeChar(v); } } UnsafeByteArrayOutputStream();  UnsafeByteArrayOutputStream(int size);  UnsafeByteArrayOutputStream(byte[] buf);  UnsafeByteArrayOutputStream(byte[] buf, int pos); @Override byte[] getByteArray(); @Override byte[] toByteArray(); @Override byte[] toByteArray(int offset, int length); @Override void reset(); @Override int getPos(); @Override void write(int b); @Override void write(byte[] b); @Override void write(byte[] b, int off, int len); @Override void writeBoolean(boolean v); @Override void writeByte(int v); @Override void writeShort(int v); @Override void writeChar(int v); @Override void writeChar(char v); @Override void writeInt(int v); @Override void ensureWritable(int minSize); @Override void skipBytes(int bytesToSkip); @Override void writeInt(int pos, int value); @Override void writeLong(long v); @Override void writeFloat(float v); @Override void writeDouble(double v); @Override void writeBytes(String s); @Override void writeChars(String s); @Override void writeUTF(String s);  }
@Test public void testWriteChars() throws IOException { UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream(); int length = os.getByteArray().length; StringBuilder sb = new StringBuilder(); for (int i = 0; i < length; i++) { sb.append("\u10ea"); } String s = sb.toString(); os.writeChars(s); UnsafeByteArrayInputStream is = new UnsafeByteArrayInputStream(os.getByteArray()); for (int i = 0; i < s.length(); i++) { assertEquals(s.charAt(i), is.readChar()); } os.close(); }