Package one.tranic.t.proxy
Class RequestWithProxyParser
java.lang.Object
one.tranic.t.proxy.RequestWithProxyParser
A utility class for handling HTTP connections and streams with support for proxy configurations
and asynchronous operations.
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 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 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.
-
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
-