Class ModifiedUtf8

java.lang.Object
java.nio.charset.ModifiedUtf8

public class ModifiedUtf8
extends Object
  • Method Summary

    Modifier and Type Method Description
    static long countBytes​(String s, boolean shortLength)
    Returns the number of bytes the modified UTF-8 representation of 's' would take.
    static String decode​(byte[] in, char[] out, int offset, int utfSize)
    Decodes a byte array containing modified UTF-8 bytes into a string.
    static void encode​(byte[] dst, int offset, String s)
    Encodes the modified UTF-8 bytes corresponding to string s into the byte array dst, starting at the given offset.
    static byte[] encode​(String s)
    Returns an array containing the modified UTF-8 form of s, using a big-endian 16-bit length.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • decode

      public static String decode​(byte[] in, char[] out, int offset, int utfSize) throws UTFDataFormatException
      Decodes 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

      public static long countBytes​(String s, boolean shortLength) throws UTFDataFormatException
      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. If shortLength is true, we'll throw an exception if the string is too long for its length to be represented by a short.
      Throws:
      UTFDataFormatException
    • encode

      public static void encode​(byte[] dst, int offset, String s)
      Encodes the modified UTF-8 bytes corresponding to string s into the byte array dst, starting at the given offset.
    • encode

      public static byte[] encode​(String s) throws UTFDataFormatException
      Returns an array containing the modified UTF-8 form of s, using a big-endian 16-bit length. Throws UTFDataFormatException if s is too long for a two-byte length.
      Throws:
      UTFDataFormatException