UTF8StringUtil { public static int getStringLength(byte[] b, int s) { int len = getUTFLength(b, s); int pos = s + getNumBytesToStoreLength(len); int end = pos + len; int charCount = 0; while (pos < end) { charCount++; pos += charSize(b, pos); } return charCount; }  static char charAt(byte[] b, int s); static int charSize(byte[] b, int s); static int getModifiedUTF8Len(char c); static int writeCharAsModifiedUTF8(char c, DataOutput dos); static int writeCharAsModifiedUTF8(char c, OutputStream dos); static int getStringLength(byte[] b, int s); static int getUTFLength(byte[] b, int s); static int getNumBytesToStoreLength(int strlen); static int UTF8ToCodePoint(byte[] b, int s); static int codePointToUTF8(int c, byte[] outputUTF8); static int normalize(byte[] bytes, int start); static int compareTo(byte[] thisBytes, int thisStart, byte[] thatBytes, int thatStart); static int rawByteCompareTo(byte[] thisBytes, int thisStart, byte[] thatBytes, int thatStart); static int lowerCaseCompareTo(byte[] thisBytes, int thisStart, byte[] thatBytes, int thatStart); static int hash(byte[] bytes, int start, int coefficient, int r); static int hash(byte[] bytes, int start); static int rawBytehash(byte[] bytes, int start); static int lowerCaseHash(byte[] bytes, int start); static StringBuilder toString(StringBuilder builder, byte[] bytes, int start); static void printUTF8StringWithQuotes(byte[] b, int s, int l, OutputStream os); static void printUTF8StringNoQuotes(byte[] b, int s, int l, OutputStream os); static void printUTF8StringWithQuotes(String str, OutputStream os); static void printUTF8StringNoQuotes(String str, OutputStream os); static int encodeUTF8Length(int length, byte[] bytes, int start); static int writeUTF8Length(int length, byte[] bytes, DataOutput out); static byte[] writeStringToBytes(String string); static String readUTF8(DataInput in); static String readUTF8(DataInput in, UTF8StringReader reader); static void writeUTF8(CharSequence str, DataOutput out); static void writeUTF8(CharSequence str, DataOutput out, UTF8StringWriter writer);  }
@Test public void testGetStringLength() throws Exception { byte[] buffer = writeStringToBytes(STRING_UTF8_MIX); assertEquals(STRING_UTF8_MIX.length(), getStringLength(buffer, 0)); }