Serializer { public void writeChar(char c) { BigEndianCodec.putChar(_getBuffer(2), _index, c); _index += 2; } Serializer(); ByteBuffer toByteBuffer(); void writeBoolean(boolean b); void writeByte(byte b); void writeChar(char c); void writeDouble(double d); void writeFloat(float f); void writeInt(int i); void writeLong(long l); void writeObject(Serializable serializable); void writeShort(short s); void writeString(String s); void writeTo(OutputStream outputStream);  }
@Test public void testWriteChar() { Serializer serializer = new Serializer(); ByteBuffer byteBuffer = ByteBuffer.allocate(_COUNT * 2); byteBuffer.order(ByteOrder.BIG_ENDIAN); CharBuffer charBuffer = byteBuffer.asCharBuffer(); char[] chars = new char[_COUNT]; for (int i = 0; i < _COUNT; i++) { chars[i] = (char)_random.nextInt(); serializer.writeChar(chars[i]); charBuffer.put(chars[i]); } ByteBuffer serializerByteBuffer = serializer.toByteBuffer(); Assert.assertArrayEquals( byteBuffer.array(), serializerByteBuffer.array()); }