Class URLUtils

java.lang.Object
io.mola.galimatias.URLUtils

public final class URLUtils extends Object
Utils for parsing and serializing URLs. Not to be confused with the URLUtils from the WHATWG URL spec.
  • Field Details

    • UTF_8

      public static final Charset UTF_8
    • idna

      private static final com.ibm.icu.text.IDNA idna
    • _hex

      private static final char[] _hex
    • RELATIVE_SCHEMES

      private static final List<String> RELATIVE_SCHEMES
  • Constructor Details

    • URLUtils

      private URLUtils()
  • Method Details

    • percentDecode

      public static String percentDecode(String input)
      Percent-decodes a string. Percent-encoded bytes are assumed to represent UTF-8 characters.
      Parameters:
      input -
      Returns:
      See Also:
    • domainToASCII

      public static String domainToASCII(String domain) throws GalimatiasParseException
      Converts a domain to its ASCII representation. Uses the the name to ASCII as specified in the IDNA standard.
      Parameters:
      domain -
      Returns:
      Throws:
      GalimatiasParseException
      See Also:
    • domainToASCII

      static String domainToASCII(String domain, ErrorHandler errorHandler) throws GalimatiasParseException
      Throws:
      GalimatiasParseException
    • domainToUnicode

      public static String domainToUnicode(String asciiDomain) throws GalimatiasParseException
      Converts a domain to its Unicode representation. Uses the the name to Unicode as specified in the IDNA standard.
      Parameters:
      asciiDomain -
      Returns:
      Throws:
      GalimatiasParseException
      See Also:
    • domainToUnicode

      static String domainToUnicode(String asciiDomain, ErrorHandler errorHandler) throws GalimatiasParseException
      Throws:
      GalimatiasParseException
    • processIdnaInfo

      private static void processIdnaInfo(ErrorHandler errorHandler, com.ibm.icu.text.IDNA.Info idnaInfo) throws GalimatiasParseException
      Throws:
      GalimatiasParseException
    • isASCIIHexDigit

      public static boolean isASCIIHexDigit(int c)
    • isASCIIDigit

      public static boolean isASCIIDigit(int c)
    • isASCIIAlphaUppercase

      public static boolean isASCIIAlphaUppercase(int c)
    • isASCIIAlphaLowercase

      public static boolean isASCIIAlphaLowercase(int c)
    • isASCIIAlpha

      public static boolean isASCIIAlpha(int c)
    • isASCIIAlphanumeric

      public static boolean isASCIIAlphanumeric(int c)
    • isURLCodePoint

      public static boolean isURLCodePoint(int c)
    • byteToHex

      static void byteToHex(byte b, StringBuilder buffer)
    • hexToInt

      public static int hexToInt(char c1, char c2)
    • percentEncode

      public static void percentEncode(byte b, StringBuilder buffer)
    • isRelativeScheme

      public static boolean isRelativeScheme(String scheme)
      Returns true if the schema is a known relative schema (ftp, file, gopher, http, https, ws, wss).
      Parameters:
      scheme -
      Returns:
    • getDefaultPortForScheme

      public static String getDefaultPortForScheme(String scheme)
      Gets the default port for a given schema. That is:
      1. ftp - 21
      2. file - null
      3. gopher - 70
      4. http - 80
      5. https - 443
      6. ws - 80
      7. wss - 433
      Parameters:
      scheme -
      Returns: