Class ConversionUtils

  • All Implemented Interfaces:

    
    public class ConversionUtils
    
                        

    General purpose conversion utilities related to HTTP/HTML

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

      • ConversionUtils

        ConversionUtils()
    • Method Detail

      • getEncodingFromContentType

         static String getEncodingFromContentType(String contentType)

        Extract the encoding (charset) from the Content-Type, e.g. "text/html; charset=utf-8".

        Parameters:
        contentType - string from which the encoding should be extracted
      • percentEncode

        @API(status = API.Status.MAINTAINED, since = "5.6") static String percentEncode(String value)

        Encodes strings for multipart/form-data names and values. The encoding is " as %22, CR as %0D, and LF as %0A. Note: % is not encoded, so it creates ambiguity which might be resolved in a later specification version.

        Parameters:
        value - input value to convert
      • encodeWithEntities

        @API(status = API.Status.EXPERIMENTAL, since = "5.6.1") static String encodeWithEntities(String value, Charset charset)

        Encodes non-encodable characters as HTML entities like e.g. 😂 for 😂.

        Parameters:
        value - value to encode
        charset - charset that will be used for encoding, defaults to UTF-8 if null
      • makeRelativeURL

         static URL makeRelativeURL(URL baseURL, String location)

        Generate an absolute URL from a possibly relative location, allowing for extraneous leading "../" segments. The Java URL constructor does not remove these.

        Parameters:
        baseURL - the base URL which is used to resolve missing protocol/host in the location
        location - the location, possibly with extraneous leading "..
      • sanitizeUrl

         static URI sanitizeUrl(URL url)

        Checks a URL and encodes it if necessary, i.e. if it is not currently correctly encoded. Warning: it may not work on all unencoded URLs.

        Parameters:
        url - non-encoded URL
      • removeSlashDotDot

         static String removeSlashDotDot(String url)

        collapses absolute or relative URLs containing '/..' converting http://host/path1/../path2 to http://host/path2 or /one/two/../three to /one/three

        Parameters:
        url - in which the '/..