Class UTF8

java.lang.Object
org.webpki.util.UTF8

public class UTF8 extends Object
Encodes/decodes UTF-8 data.
  • Method Details

    • encode

      public static byte[] encode(String utf16String)
      Encodes Java (UTF-16) String to UTF-8.

      This method was added because String.getBytes("utf-8") does not flag invalid UTF-16.

      Parameters:
      utf16String - String presumably holding valid UTF-16
      Returns:
      UTF-8 byte array
      Throws:
      IllegalArgumentException
    • decode

      public static String decode(byte[] utf8Bytes)
      Decodes a UTF-8 byte array into a String.

      This method was added because new String(byteArray, "utf-8") does not flag invalid UTF-8.

      Parameters:
      utf8Bytes - Binary data presumably holding valid UTF-8
      Returns:
      Java (UTF-16) String
      Throws:
      IllegalArgumentException