Package fr.dyade.aaa.common.encoding
Class Utf8
- java.lang.Object
-
- fr.dyade.aaa.common.encoding.Utf8
-
public final class Utf8 extends Object
Low-level, high-performance utility methods related to the UTF-8 character encoding. UTF-8 is defined in section D92 of The Unicode Standard Core Specification, Chapter 3.The variant of UTF-8 implemented by this class is the restricted definition of UTF-8 introduced in Unicode 3.1. One implication of this is that it rejects "non-shortest form" byte sequences, even though the JDK decoder may accept them.
- Since:
- 16.0
- Author:
- Martin Buchholz, Clément Roux
-
-
Constructor Summary
Constructors Constructor Description Utf8()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intencodedLength(CharSequence sequence)Returns the number of bytes in the UTF-8-encoded form ofsequence.private static intencodedLengthGeneral(CharSequence sequence, int start)private static StringunpairedSurrogateMsg(int i)
-
-
-
Method Detail
-
encodedLength
public static int encodedLength(CharSequence sequence)
Returns the number of bytes in the UTF-8-encoded form ofsequence. For a string, this method is equivalent tostring.getBytes(UTF_8).length, but is more efficient in both time and space.- Throws:
IllegalArgumentException- ifsequencecontains ill-formed UTF-16 (unpaired surrogates)
-
encodedLengthGeneral
private static int encodedLengthGeneral(CharSequence sequence, int start)
-
unpairedSurrogateMsg
private static String unpairedSurrogateMsg(int i)
-
-