Class NetworkUtils

java.lang.Object
org.polyfrost.oneconfig.utils.v1.NetworkUtils

public final class NetworkUtils extends Object
Utility class for accessing the internet.
  • Field Details

  • Method Details

    • getString

      @Nullable public static @Nullable String getString(String url, String userAgent, int timeout, boolean useCaches)
      Gets the contents of a URL as a String.
      Parameters:
      url - The URL to read.
      userAgent - The user agent to use.
      timeout - The timeout in milliseconds.
      useCaches - Whether to use caches.
      Returns:
      The contents of the URL, or null if the request failed.
    • getString

      @Nullable public static @Nullable String getString(String url)
      Gets the contents of a URL as a String.
      Parameters:
      url - The URL to read.
      Returns:
      The contents of the URL, or null if the request failed.
      See Also:
    • downloadFile

      public static boolean downloadFile(String url, Path path, String userAgent, int timeout, boolean useCaches)
      Downloads a path from a URL.
      Parameters:
      url - The URL to download from.
      path - The path to download to.
      userAgent - The user agent to use.
      timeout - The timeout in milliseconds.
      useCaches - Whether to use caches.
      Returns:
      Whether the download was successful.
    • downloadFile

      public static boolean downloadFile(String url, Path path)
      Downloads a file from a URL.
      Parameters:
      url - The URL to download from.
      path - The file to download to.
      Returns:
      Whether the download was successful.
      See Also:
    • browseLink

      public static void browseLink(String uri)
      Launches a URL in the default browser.
      Parameters:
      uri - The URI to launch
      See Also:
    • setupConnection

      public static InputStream setupConnection(String url) throws IOException
      Throws:
      IOException
    • setupConnection

      public static InputStream setupConnection(String url, String userAgent, int timeout, boolean useCaches) throws IOException
      Throws:
      IOException