Class Text

java.lang.Object
dev.gmitch215.bytebox.builtin.Text

public final class Text extends Object
The platform's own encoders, exposed as themselves.

Every charset beyond UTF-8 costs a table in the binary if the class library provides it, and the isolate already has TextDecoder, which handles every encoding the WHATWG registry lists. Base64 and hexadecimal are here for the same reason: the platform has them and a Java implementation would be bytes spent on something already present.

Since:
1.0.0
  • Method Details

    • encode

      public static org.teavm.jso.typedarrays.Uint8Array encode(String text)
      Encodes text as UTF-8.
      Parameters:
      text - the text
      Returns:
      the bytes
    • decode

      public static String decode(org.teavm.jso.typedarrays.ArrayBuffer bytes)
      Decodes UTF-8.
      Parameters:
      bytes - the bytes
      Returns:
      the text
    • decode

      public static String decode(org.teavm.jso.typedarrays.ArrayBuffer bytes, String encoding)
      Decodes bytes in a named encoding.
      Parameters:
      bytes - the bytes
      encoding - a WHATWG label, such as shift_jis or windows-1252
      Returns:
      the text
    • decode

      public static String decode(byte[] bytes)
      Decodes UTF-8.
      Parameters:
      bytes - the bytes
      Returns:
      the text
    • decode

      public static String decode(byte[] bytes, String encoding)
      Decodes bytes in a named encoding.
      Parameters:
      bytes - the bytes
      encoding - a WHATWG label, such as shift_jis or windows-1252
      Returns:
      the text
    • supports

      public static boolean supports(String encoding)
      Reports whether the runtime knows an encoding.
      Parameters:
      encoding - a WHATWG label
      Returns:
      whether a decoder can be built for it
    • toBase64

      public static String toBase64(org.teavm.jso.typedarrays.ArrayBuffer bytes)
      Encodes bytes as base64.
      Parameters:
      bytes - the bytes
      Returns:
      the base64 text
    • toBase64

      public static String toBase64(byte[] bytes)
      Encodes bytes as base64.
      Parameters:
      bytes - the bytes
      Returns:
      the base64 text
    • fromBase64

      public static org.teavm.jso.typedarrays.ArrayBuffer fromBase64(String base64)
      Decodes base64.
      Parameters:
      base64 - the base64 text
      Returns:
      the bytes
    • toHex

      public static String toHex(org.teavm.jso.typedarrays.ArrayBuffer bytes)
      Encodes bytes as lowercase hexadecimal.
      Parameters:
      bytes - the bytes
      Returns:
      the hexadecimal text
    • toHex

      public static String toHex(byte[] bytes)
      Encodes bytes as lowercase hexadecimal.
      Parameters:
      bytes - the bytes
      Returns:
      the hexadecimal text
    • fromHex

      public static org.teavm.jso.typedarrays.ArrayBuffer fromHex(String hex)
      Decodes hexadecimal.
      Parameters:
      hex - the hexadecimal text, with an even number of digits
      Returns:
      the bytes
    • urlEncode

      public static String urlEncode(String value)
      Percent-encodes a value for use in a URL.
      Parameters:
      value - the value
      Returns:
      the encoded value
    • urlDecode

      public static String urlDecode(String value)
      Parameters:
      value - the encoded value
      Returns:
      the decoded value