Class RequestWithProxyParser
This class provides methods to open URL connections and input streams synchronously or asynchronously, applying proxy settings retrieved automatically from the environment or system configuration.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpURLConnectionopenConnection(String url) Opens a connection to the specified URL string with proxy settings applied.static HttpURLConnectionopenConnection(URL url) Opens a connection to the specified URL using the proxy configuration retrieved from the system or environment settings.static Future<HttpURLConnection>Establishes an asynchronous connection to the specified URL.static Future<HttpURLConnection>openConnectionAsync(URL url) Opens a connection to the specified URL asynchronously and returns a Future with the result.static InputStreamopenStream(String url) Opens an input stream to the resource referenced by the specified URL string.static InputStreamopenStream(URL url) Opens a stream for reading from the specifiedURL, using a proxy configuration retrieved viaProxyConfigReader.getProxy().static Future<InputStream>openStreamAsync(String url) Asynchronously opens an input stream to the specified URL string.static Future<InputStream>openStreamAsync(URL url) Opens a stream to a given URL asynchronously using an executor service.static voidRefreshes the proxy configuration used by the application.static voidsetCustomProxy(Proxy proxy) Sets a custom proxy for the RequestWithProxyParser class.
-
Constructor Details
-
RequestWithProxyParser
public RequestWithProxyParser()
-
-
Method Details
-
setCustomProxy
Sets a custom proxy for the RequestWithProxyParser class.- Parameters:
proxy- the Proxy instance to be set as the custom proxy. This proxy will be used for subsequent network requests within this class.
-
refreshProxy
public static void refreshProxy()Refreshes the proxy configuration used by the application.This method retrieves the current proxy settings by invoking the `ProxyConfigReader.getProxy()` method and updates the static `proxy` field with the newly retrieved proxy configuration. It is useful in scenarios where the proxy settings might have changed dynamically and need to be reloaded.
-
openConnectionAsync
Opens a connection to the specified URL asynchronously and returns a Future with the result.The connection is established using proxy settings if applicable.
- Parameters:
url- the URL to which the connection should be opened- Returns:
- a Future containing the established HttpURLConnection, or a RuntimeException if an error occurs
- Throws:
IOException- if an IO error occurs while attempting to open the connection
-
openConnectionAsync
Establishes an asynchronous connection to the specified URL.- Parameters:
url- the URL as a string to which the connection should be opened.- Returns:
- a Future representing the pending result of the HttpURLConnection.
- Throws:
IOException- if an error occurs while forming or opening the connection.
-
openConnection
Opens a connection to the specified URL string with proxy settings applied.- Parameters:
url- the URL string to which a connection is to be opened- Returns:
- a HttpURLConnection object pointing to the specified resource
- Throws:
IOException- if an I/O error occurs while opening the connection
-
openConnection
Opens a connection to the specified URL using the proxy configuration retrieved from the system or environment settings.- Parameters:
url- the URL to which the connection needs to be established.- Returns:
- an instance of
HttpURLConnectionrepresenting the connection to the specified URL. - Throws:
IOException- if an I/O exception occurs while opening the connection.
-
openStream
Opens a stream for reading from the specifiedURL, using a proxy configuration retrieved viaProxyConfigReader.getProxy().- Parameters:
url- theURLfrom which the stream should be opened- Returns:
- an
InputStreamto read from the givenURL - Throws:
IOException- if an I/O error occurs while opening the connection or stream
-
openStream
Opens an input stream to the resource referenced by the specified URL string.- Parameters:
url- the URL string pointing to the resource to be accessed- Returns:
- an InputStream to read data from the specified resource
- Throws:
IOException- if an I/O exception occurs while trying to open the stream
-
openStreamAsync
Opens a stream to a given URL asynchronously using an executor service.The returned
Futureallows retrieving the resultingInputStreamwhen the operation completes. If an I/O error occurs during the stream opening, the exception will be encapsulated in aRuntimeException.- Parameters:
url- the URL to open a stream to; must not be null- Returns:
- a
Futurerepresenting the pending result of the operation, which will yield anInputStreamupon successful completion - Throws:
IOException- if an error occurs while initializing the URL stream
-
openStreamAsync
Asynchronously opens an input stream to the specified URL string. This method submits a task to an executor for opening the stream and returns a Future representing the pending result.- Parameters:
url- the string representation of the URL to open a stream from- Returns:
- a Future containing the InputStream associated with the specified URL
- Throws:
IOException- if an I/O error occurs while creating the URL or accessing its stream
-