CharSequenceCodec implements ICharSequenceCodec { @Override public byte[] encode(@Nonnull final CharSequence message) throws EncodingException { try { ByteBuffer encodedBuffer = encoder.encode(CharBuffer.wrap(message)); byte[] bufferCopy = new byte[encodedBuffer.limit()]; System.arraycopy(encodedBuffer.array(), 0, bufferCopy, 0, encodedBuffer.limit()); return bufferCopy; } catch (CharacterCodingException e) { throw new EncodingException("UTF-8 encoding has been failed because: " + e.getMessage(), e); } } private  CharSequenceCodec(final String name); static CharSequenceCodec create(final String name); @Override byte[] encode(@Nonnull final CharSequence message); @Override String decode(@Nonnull final byte[] message);  }
@Test public void encodeHexTest() throws EncodingException { byte[] utf8EncodeResult = charSequenceCodec.encode(SOURCE_MSG); assertTrue(Arrays.equals(utf8EncodeResult, UTF_8_MSG)); }