|
Bouncy Castle Cryptography Library 1.87 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.bouncycastle.util.encoders.UTF8
Utilities for working with UTF-8 encodings.
Decoding of UTF-8 is based on a presentation by Bob Steagall at CppCon2018 (see https://github.com/BobSteagall/CppCon2018). It uses a Deterministic Finite Automaton (DFA) to recognize and decode multi-byte code points.
| Constructor Summary | |
UTF8()
|
|
| Method Summary | |
static int |
transcodeToUTF16(byte[] utf8,
char[] utf16)
Transcode a UTF-8 encoding into a UTF-16 representation. |
static int |
transcodeToUTF16(byte[] utf8,
int utf8Off,
int utf8Length,
char[] utf16)
Transcode a UTF-8 encoding into a UTF-16 representation. |
static int |
transcodeToUTF16(byte[] utf8,
int utf8Off,
int utf8Length,
char[] utf16,
boolean lenient)
Transcode a UTF-8 encoding into a UTF-16 representation, optionally replacing malformed input rather than failing. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public UTF8()
| Method Detail |
public static int transcodeToUTF16(byte[] utf8,
char[] utf16)
utf8 - A non-null array containing a well-formed UTF-8 encoding.utf16 - A non-null array, at least as long as the array in order to ensure
the output will fit.
public static int transcodeToUTF16(byte[] utf8,
int utf8Off,
int utf8Length,
char[] utf16)
utf8 - A non-null array containing a well-formed UTF-8 encoding.utf8Off - start position in the array for the well-formed encoding.utf8Length - length in bytes of the well-formed encoding.utf16 - A non-null array, at least as long as the array in order to ensure
the output will fit.
public static int transcodeToUTF16(byte[] utf8,
int utf8Off,
int utf8Length,
char[] utf16,
boolean lenient)
With false this behaves exactly as
transcodeToUTF16(byte[], int, int, char[]). With true, each maximal
subpart of an ill-formed sequence is replaced by a single U+FFFD REPLACEMENT CHARACTER, as
recommended in the Unicode Standard, ch. 3, "U+FFFD Substitution of Maximal Subparts" (the
practice the WHATWG Encoding Standard also requires): a byte that cannot begin a sequence is
replaced on its own, a sequence broken by an unexpected byte is replaced up to but not
including that byte, which is then decoded afresh, and a sequence truncated by the end of the
input is replaced. Well-formed input is decoded identically in either mode, and no unmatched
surrogates are produced. Each replacement accounts for at least one input byte, so an output
array at least as long as the input is still sufficient; -1 is then returned only if
is too small.
utf8 - A non-null array containing a UTF-8 encoding.utf8Off - start position in the array for the encoding.utf8Length - length in bytes of the encoding.utf16 - A non-null array, at least as long as in order to ensure
the output will fit.lenient - true to replace malformed input with U+FFFD, false to fail on it.
|
Bouncy Castle Cryptography Library 1.87 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||