Package org.geysermc.geyser.util
Class WebUtils
java.lang.Object
org.geysermc.geyser.util.WebUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddownloadFile(String reqURL, String fileLocation) Downloads a file from the given URL and saves it to diskstatic @Nullable PathdownloadRemotePack(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 itstatic String @Nullable []findSrvRecord(GeyserImpl geyser, String remoteAddress) Find a SRV record for the given addressstatic StringMakes a web request to the given URL and returns the body as a stringstatic com.fasterxml.jackson.databind.JsonNodeMakes a web request to the given URL and returns the body as aJsonNode.getLineStream(String reqURL) Get a stream of lines from the given URLstatic Stringstatic StringPost a string to the given URLstatic StringPost fields to a URL as a form
-
Constructor Details
-
WebUtils
public WebUtils()
-
-
Method Details
-
getBody
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
Makes a web request to the given URL and returns the body as aJsonNode.- Parameters:
reqURL- URL to fetch- Returns:
- the response as JSON
- Throws:
IOException
-
downloadFile
Downloads a file from the given URL and saves it to disk- Parameters:
reqURL- File to fetchfileLocation- Location to save on disk
-
downloadRemotePack
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 checkforce- 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
Post a string to the given URL- Parameters:
reqURL- URL to post topostContent- String data to post- Returns:
- String returned by the server
- Throws:
IOException- If the request fails
-
postForm
Post fields to a URL as a form- Parameters:
reqURL- URL to post tofields- Form data to post- Returns:
- String returned by the server
- Throws:
IOException- If the request fails
-
findSrvRecord
Find a SRV record for the given address- Parameters:
geyser- Geyser instanceremoteAddress- Address to find the SRV record for- Returns:
- The SRV record or null if not found
-
getLineStream
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
-