Class WebUtilities

  • All Implemented Interfaces:

    
    public final class WebUtilities
    
                        

    Utility-class revolving around interactions with web-resources.

    Author:

    Griefed

    • 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
    • Method Summary

      Modifier and Type Method Description
      final Boolean downloadAndReplaceFile(File fileDestination, URL downloadURL) Download the file from the specified URL to the specified destination, replacing the file if it already exists.
      final Boolean downloadFile(File file, URL downloadURL) Download the file from the specified URL to the specified destination.
      final Unit openLinkInBrowser(URL url) Open the given url in a browser.
      final Unit openLinkInBrowser(URI uri) Open the given uri in a browser.
      final Boolean hasteBinPreChecks(File fileToCheck) Checks the filesize of the given file whether it is smaller or bigger than 10 MB.
      final String createHasteBinFromString(String text) Create a HasteBin post from a given string.
      final String createHasteBinFromFile(File textFile) Create a HasteBin post from a given text file.
      final String getResponseAsString(URL url) Get the response of a call to a URL as a string.
      final Integer getResponseCode(URL url) Get the response-code of a call to a URL as an integer.
      final Boolean isReachable(URL url) Check the availability of the host of the given URL and whether the URL gives a status code of
      • Only when both the host is available and the URL returns a status code of 200 does this method return true.

      • Methods inherited from class java.lang.Object

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

      • WebUtilities

        WebUtilities(ApiProperties apiProperties)
        Parameters:
        apiProperties - API configuration of this instance.
    • Method Detail

      • downloadAndReplaceFile

         final Boolean downloadAndReplaceFile(File fileDestination, URL downloadURL)

        Download the file from the specified URL to the specified destination, replacing the file if it already exists. The destination should end in a valid filename. Any directories up to the specified file will be created.

        Parameters:
        fileDestination - The file to store the web-resource in.
        downloadURL - The URL to the file you want to download.
        Returns:

        Boolean. Returns true if the file could be found on the hosts' filesystem.

      • downloadFile

         final Boolean downloadFile(File file, URL downloadURL)

        Download the file from the specified URL to the specified destination. The destination should end in a valid filename. Any directories up to the specified file will be created.

        Parameters:
        file - The destination where the file should be stored.
        downloadURL - The URL to the file you want to download.
        Returns:

        true if the file was created.

      • openLinkInBrowser

         final Unit openLinkInBrowser(URL url)

        Open the given url in a browser.

        Parameters:
        url - The URI to the website you want to open.
      • openLinkInBrowser

         final Unit openLinkInBrowser(URI uri)

        Open the given uri in a browser.

        Parameters:
        uri - The URI to the website you want to open.
      • hasteBinPreChecks

         final Boolean hasteBinPreChecks(File fileToCheck)

        Checks the filesize of the given file whether it is smaller or bigger than 10 MB.

        Parameters:
        fileToCheck - The file or directory to check.
        Returns:

        Boolean. True if the file is smaller, false if the file is bigger than 10 MB.

      • createHasteBinFromString

         final String createHasteBinFromString(String text)

        Create a HasteBin post from a given string. The text provided passed onto Haste zneix which creates a HasteBin post out of the passed String and returns the URL to the newly created post.

        Created with the help of kaimu-ken's hastebin.java (MIT License) and edited to use HasteBin fork zneix/haste-server. My fork of kaimu-kun's hastebin.java is available at Griefed/hastebin.java.

        Parameters:
        text - The file which will be read into a String of which then to create a HasteBin post of.
        Returns:

        String. Returns a String containing the URL to the newly created HasteBin post.

      • createHasteBinFromFile

         final String createHasteBinFromFile(File textFile)

        Create a HasteBin post from a given text file. The text file provided is read into a string and then passed onto Haste zneix which creates a HasteBin post out of the passed String and returns the URL to the newly created post.

        Created with the help of kaimu-ken's hastebin.java (MIT License) and edited to use HasteBin fork zneix/haste-server. My fork of kaimu-kun's hastebin.java is available at Griefed/hastebin.java.

        Parameters:
        textFile - The file which will be read into a String of which then to create a HasteBin post of.
        Returns:

        String. Returns a String containing the URL to the newly created HasteBin post.

      • getResponseAsString

         final String getResponseAsString(URL url)

        Get the response of a call to a URL as a string.

        Parameters:
        url - The URL you want to get the response from
        Returns:

        The response.

      • getResponseCode

         final Integer getResponseCode(URL url)

        Get the response-code of a call to a URL as an integer.

        Parameters:
        url - The URL you want to get the response from
        Returns:

        The response.

      • isReachable

         final Boolean isReachable(URL url)

        Check the availability of the host of the given URL and whether the URL gives a status code of

        • Only when both the host is available and the URL returns a status code of 200 does this method return true.

        Parameters:
        url - The URL of which to check for host-availability.
        Returns:

        true if, and only if, the host is available and the URL returns the status code 200.