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)
      Makes a web request to the given URL and returns the body as a string
      Parameters:
      reqURL - URL to fetch
      Returns:
      Body contents or error message if the request fails
    • 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
    • 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()