Class HTTPUtil


  • public final class HTTPUtil
    extends Object
    This class provides methods for working with URL's
    • Method Detail

      • isURL

        public static boolean isURL​(String url)
        Checks if the given String is an URL
        Parameters:
        url - URL
        Returns:
        True if the given String is an URL, false otherwise
      • trimURL

        public static String trimURL​(String url)
        Trims an url
        Parameters:
        url - URL
        Returns:
        Trimmed URL
      • encodeURL

        public static String encodeURL​(String url,
                                       boolean checkForPercentCharacter)
        Encodes the given URL. If the method fails to encode the URL the given URL is returned. If the checkForPercentCharacter is true and a percent character is found in the URL, then the URL will not be encoded and just returned.
        Parameters:
        url - Decoded URL
        checkForPercentCharacter - Flag if URL should be checked for percent character to prevent double encoding
        Returns:
        Encoded URL
      • encodeURL

        public static String encodeURL​(String url)
        Encodes the given URL. If the method fails to encode the URL the given URL is returned. Only unencoded/decoded URLs should be passed to this method, because encoded URLs would be encoded again!
        Parameters:
        url - Decoded URL
        Returns:
        Encoded URL
      • decodeURL

        public static String decodeURL​(String url)
        Decodes the given URL. If the method fails to decode the URL the given URL is returned.
        Parameters:
        url - Encoded URL
        Returns:
        Decoded URL
      • getDomainFromURL

        public static String getDomainFromURL​(String url)
        Returns the domain of a URL If the domain could not be found an empty String is returned
        Parameters:
        url - URL
        Returns:
        Domain
      • getDomainAndPathFromURL

        public static String[] getDomainAndPathFromURL​(String url)
        Returns the domain and path part of a URL If the url could not be splitted, null is returned
        Parameters:
        url - URL
        Returns:
        String-Array
      • getTLDName

        public static String getTLDName​(String domain)
        Returns only the name of a TLD
        Parameters:
        domain - Domain
        Returns:
        TLD-Name
      • getFilenameFromURL

        public static String getFilenameFromURL​(String url,
                                                String defaultValue)
        Returns the filename from the url if possible or otherwise the defaultValue
        Parameters:
        url - URL
        defaultValue - DefaultValue
        Returns:
        Filename
      • getBaseURL

        public static String getBaseURL​(String url)
        Parameters:
        url - URL
        Returns:
        Base-URL
      • convertURLFromRelativeToAbsolute

        public static String convertURLFromRelativeToAbsolute​(String referrer,
                                                              String urlToConvert)
        Parameters:
        referrer -
        urlToConvert - URL
        Returns:
        Converted URL