Package libcore.net

Class UriCodec

java.lang.Object
libcore.net.UriCodec

public abstract class UriCodec
extends Object
Encodes and decodes application/x-www-form-urlencoded content. Subclasses define exactly which characters are legal.

By default, UTF-8 is used to encode escaped characters. A single input character like "€" may be encoded to multiple octets like %C2%80.

  • Constructor Details

    • UriCodec

      public UriCodec()
  • Method Details

    • isRetained

      protected abstract boolean isRetained​(char c)
      Returns true if c does not need to be escaped.
    • validate

      public final String validate​(String uri, int start, int end, String name) throws URISyntaxException
      Throws if s is invalid according to this encoder.
      Throws:
      URISyntaxException
    • validateSimple

      public static void validateSimple​(String s, String legal) throws URISyntaxException
      Throws if s contains characters that are not letters, digits or in legal.
      Throws:
      URISyntaxException
    • encode

      public final String encode​(String s, Charset charset)
    • appendEncoded

      public final void appendEncoded​(StringBuilder builder, String s)
    • appendPartiallyEncoded

      public final void appendPartiallyEncoded​(StringBuilder builder, String s)
    • decode

      public static String decode​(String s, boolean convertPlus, Charset charset, boolean throwOnFailure)
      Parameters:
      convertPlus - true to convert '+' to ' '.
      throwOnFailure - true to throw an IllegalArgumentException on invalid escape sequences; false to replace them with the replacement character (U+fffd).
    • decode

      public static String decode​(String s)