Class WebUtils

java.lang.Object
org.geysermc.geyser.util.WebUtils

public class WebUtils extends Object
  • Constructor Details

    • WebUtils

      public WebUtils()
  • Method Details

    • getBody

      public static String getBody(String reqURL) throws IOException
      Makes a web request to the given URL and returns the body as a string
      Parameters:
      reqURL - URL to fetch
      Returns:
      body content or
      Throws:
      IOException - / a wrapped UnknownHostException for nicer errors.
    • getJson

      public static com.fasterxml.jackson.databind.JsonNode getJson(String reqURL) throws IOException
      Makes a web request to the given URL and returns the body as a JsonNode.
      Parameters:
      reqURL - URL to fetch
      Returns:
      the response as JSON
      Throws:
      IOException
    • downloadFile

      public static void downloadFile(String reqURL, String fileLocation)
      Downloads a file from the given URL and saves it to disk
      Parameters:
      reqURL - File to fetch
      fileLocation - Location to save on disk
    • downloadRemotePack

      public static @Nullable Path downloadRemotePack(String url, boolean force)
      Checks a remote pack URL to see if it is valid If it is, it will download the pack file and return a path to it
      Parameters:
      url - The URL to check
      force - If true, the pack will be downloaded even if it is cached to a separate location.
      Returns:
      Path to the downloaded pack file, or null if it was unable to be loaded
    • post

      public static String post(String reqURL, String postContent) throws IOException
      Post a string to the given URL
      Parameters:
      reqURL - URL to post to
      postContent - String data to post
      Returns:
      String returned by the server
      Throws:
      IOException - If the request fails
    • postForm

      public static String postForm(String reqURL, Map<String,String> fields) throws IOException
      Post fields to a URL as a form
      Parameters:
      reqURL - URL to post to
      fields - Form data to post
      Returns:
      String returned by the server
      Throws:
      IOException - If the request fails
    • findSrvRecord

      public static String @Nullable [] findSrvRecord(GeyserImpl geyser, String remoteAddress)
      Find a SRV record for the given address
      Parameters:
      geyser - Geyser instance
      remoteAddress - Address to find the SRV record for
      Returns:
      The SRV record or null if not found
    • getLineStream

      public static Stream<String> getLineStream(String reqURL)
      Get a stream of lines from the given URL
      Parameters:
      reqURL - URL to fetch
      Returns:
      Stream of lines from the URL or an empty stream if the request fails
    • getUserAgent

      public static String getUserAgent()