ModifiedUTF8Charset extends BaseCharset { static public int calculateByteLength(CharSequence charSeq) { return calculateByteLength(charSeq, null, 0, 0); } ModifiedUTF8Charset(); @Override int estimateEncodeByteLength(CharSequence str0); @Override int estimateDecodeCharLength(byte[] bytes); @Override byte[] encode(CharSequence charSeq); @Override void decode(byte[] bytes, StringBuilder buffer); @Override String decode(byte[] bytes); String decode(byte[] bytes, int offset, int length); static int calculateByteLength(CharSequence charSeq); static int calculateByteLength(CharSequence charSeq, char[] charBuffer, int charOffset, int charLength); static int encodeToByteArray(CharSequence charSeq, char[] charBuffer, int charOffset, int charLength, byte[] byteBuffer, int byteOffset); static int decodeToCharArray(byte[] byteBuffer, int byteOffset, int byteLength, char[] charBuffer, int charOffset);  }
@Test public void calculateByteLength() throws Exception { String sample = null; Assert.assertEquals(0, ModifiedUTF8Charset.calculateByteLength(null)); Assert.assertEquals(0, ModifiedUTF8Charset.calculateByteLength("")); Assert.assertEquals(1, ModifiedUTF8Charset.calculateByteLength("a")); Assert.assertEquals(2, ModifiedUTF8Charset.calculateByteLength("\n\r")); sample = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; Assert.assertEquals(sample.getBytes("UTF8").length, ModifiedUTF8Charset.calculateByteLength(sample)); sample = "\u20ac"; Assert.assertEquals(sample.getBytes("UTF8").length, ModifiedUTF8Charset.calculateByteLength(sample)); sample = "\u20ac\u0623"; Assert.assertEquals(sample.getBytes("UTF8").length, ModifiedUTF8Charset.calculateByteLength(sample)); sample = "\u00A7\u00E5\uFFFF"; Assert.assertEquals(sample.getBytes("UTF8").length, ModifiedUTF8Charset.calculateByteLength(sample)); }