Class URLPathEncoder


  • public final class URLPathEncoder
    extends java.lang.Object
    A simple URL path encoder.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static char[] HEXADECIMAL
      Hexadecimal digits.
      private static boolean[] safe
      Whether an ASCII character is URL-safe.
      private static java.lang.String[] SCHEME_PREFIXES
      Valid classpath URL scheme prefixes.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private URLPathEncoder()
      Constructor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String decodePath​(java.lang.String str)
      Unescape a URL segment, and turn it from UTF-8 bytes into a Java string.
      static java.lang.String encodePath​(java.lang.String path)
      Encode a URL path using percent-encoding.
      static java.lang.String normalizeURLPath​(java.lang.String urlPath)
      Normalize a URL path, so that it can be fed into the URL or URI constructor.
      private static void unescapeChars​(java.lang.String str, boolean isQuery, java.io.ByteArrayOutputStream buf)
      Unescape chars in a URL.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • safe

        private static boolean[] safe
        Whether an ASCII character is URL-safe.
      • HEXADECIMAL

        private static final char[] HEXADECIMAL
        Hexadecimal digits.
      • SCHEME_PREFIXES

        private static final java.lang.String[] SCHEME_PREFIXES
        Valid classpath URL scheme prefixes.
    • Constructor Detail

      • URLPathEncoder

        private URLPathEncoder()
        Constructor.
    • Method Detail

      • unescapeChars

        private static void unescapeChars​(java.lang.String str,
                                          boolean isQuery,
                                          java.io.ByteArrayOutputStream buf)
        Unescape chars in a URL. URLDecoder.decode is broken: https://bugs.openjdk.java.net/browse/JDK-8179507
      • decodePath

        public static java.lang.String decodePath​(java.lang.String str)
        Unescape a URL segment, and turn it from UTF-8 bytes into a Java string.
        Parameters:
        str - the str
        Returns:
        the string
      • encodePath

        public static java.lang.String encodePath​(java.lang.String path)
        Encode a URL path using percent-encoding. '/' is not encoded.
        Parameters:
        path - The path to encode.
        Returns:
        The encoded path.
      • normalizeURLPath

        public static java.lang.String normalizeURLPath​(java.lang.String urlPath)
        Normalize a URL path, so that it can be fed into the URL or URI constructor.
        Parameters:
        urlPath - the URL path
        Returns:
        the URL string