Class IpListClient
java.lang.Object
de.gustavblass.nginx.ipguard4j.IpListClient
- All Implemented Interfaces:
IpListFetcher
Downloads lists of IP addresses from given
URIs.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @NonNull okhttp3.OkHttpClientprivate static final @NonNull org.apache.logging.log4j.Loggerprivate static @Nullable StringThe user agent string that the application will send with each HTTP request.private static final @NonNull ReentrantReadWriteLockEnsures mutual exclusion when accessing theUSER_AGENT. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newIpListClientwith a defaultOkHttpClient.IpListClient(@NonNull okhttp3.OkHttpClient httpClient) Creates a newIpListClientwith the givenOkHttpClient. -
Method Summary
-
Field Details
-
LOG
@NonNull private static final @NonNull org.apache.logging.log4j.Logger LOG -
USER_AGENT
The user agent string that the application will send with each HTTP request.
Access only through
getUserAgent()! -
USER_AGENT_LOCK
Ensures mutual exclusion when accessing theUSER_AGENT. -
httpClient
-
-
Constructor Details
-
IpListClient
public IpListClient()Creates a newIpListClientwith a defaultOkHttpClient. -
IpListClient
public IpListClient(@NonNull @NonNull okhttp3.OkHttpClient httpClient) Creates a newIpListClientwith the givenOkHttpClient.- Parameters:
httpClient- ThehttpClient.
-
-
Method Details
-
fetchList
@Contract(mutates="io") @NonNull public @NonNull Stream<String> fetchList(@NonNull @NonNull URI sourceUri) throws IOException, UncheckedIOException Downloads the IP-address list from the givenURI.- Specified by:
fetchListin interfaceIpListFetcher- Parameters:
sourceUri- The address from which to download the IP address list.- Returns:
- A
Streamof the individual lines that the list consists of. - Throws:
IOException- If an error occurs while downloading the list.UncheckedIOException- If theBufferedReaderor the HTTPResponsecannot be closed after the Stream is closed.
-
getUserAgent
- Returns:
- The
USER_AGENTstring. - Implementation Note:
- Acquires the
USER_AGENT_LOCK's read lock first, and if theUSER_AGENThas not yet been computed, acquires the write lock to compute it.
-