Package java.nio.charset
Class ModifiedUtf8
java.lang.Object
java.nio.charset.ModifiedUtf8
public class ModifiedUtf8 extends Object
-
Method Summary
Modifier and Type Method Description static longcountBytes(String s, boolean shortLength)Returns the number of bytes the modified UTF-8 representation of 's' would take.static Stringdecode(byte[] in, char[] out, int offset, int utfSize)Decodes a byte array containing modified UTF-8 bytes into a string.static voidencode(byte[] dst, int offset, String s)Encodes the modified UTF-8 bytes corresponding to stringsinto the byte arraydst, starting at the givenoffset.static byte[]encode(String s)Returns an array containing the modified UTF-8 form ofs, using a big-endian 16-bit length.
-
Method Details
-
decode
public static String decode(byte[] in, char[] out, int offset, int utfSize) throws UTFDataFormatExceptionDecodes a byte array containing modified UTF-8 bytes into a string.Note that although this method decodes the (supposedly impossible) zero byte to U+0000, that's what the RI does too.
- Throws:
UTFDataFormatException
-
countBytes
Returns the number of bytes the modified UTF-8 representation of 's' would take. Note that this is just the space for the bytes representing the characters, not the length which precedes those bytes, because different callers represent the length differently, as two, four, or even eight bytes. IfshortLengthis true, we'll throw an exception if the string is too long for its length to be represented by a short.- Throws:
UTFDataFormatException
-
encode
Encodes the modified UTF-8 bytes corresponding to stringsinto the byte arraydst, starting at the givenoffset. -
encode
Returns an array containing the modified UTF-8 form ofs, using a big-endian 16-bit length. Throws UTFDataFormatException ifsis too long for a two-byte length.- Throws:
UTFDataFormatException
-