All Downloads are FREE. Search and download functionalities are using the official Maven repository.

internal.util.http.HttpURLConnectionFactoryLoader Maven / Gradle / Ivy

There is a newer version: 3.0.0-beta.13
Show newest version
package internal.util.http;

import java.lang.Iterable;
import java.lang.Long;
import java.lang.Override;
import java.util.Iterator;
import java.util.ServiceLoader;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Consumer;
import java.util.stream.StreamSupport;

/**
 * Custom service loader for {@link internal.util.http.HttpURLConnectionFactory}.
 * 
This class is thread-safe. *

Properties: *

    *
  • Quantifier: SINGLE
  • *
  • Fallback: {@link internal.util.http.DefaultHttpURLConnectionFactory}
  • *
  • Preprocessing: wrapper: none filters:[isRequired] sorters:[]
  • *
  • Mutability: NONE
  • *
  • Singleton: true
  • *
  • Name: null
  • *
  • Backend: null
  • *
  • Cleaner: null
  • *
*/ public final class HttpURLConnectionFactoryLoader { private static final Iterable SOURCE = ServiceLoader.load(HttpURLConnectionFactory.class); private static final HttpURLConnectionFactory RESOURCE = doLoad(); private HttpURLConnectionFactoryLoader() { } private static Spliterator spliterator() { return new Spliterators.AbstractSpliterator(Long.MAX_VALUE, 0) { final Iterator delegate = SOURCE.iterator(); @Override public boolean tryAdvance(Consumer action) { if (delegate.hasNext()) { action.accept((HttpURLConnectionFactory) delegate.next()); return true; } return false; } }; } private static HttpURLConnectionFactory doLoad() { return StreamSupport.stream(spliterator(), false) .filter(HttpURLConnectionFactory::isRequired) .findFirst() .orElseGet(() -> new DefaultHttpURLConnectionFactory()); } /** * Gets a {@link internal.util.http.HttpURLConnectionFactory} instance. *
This method is thread-safe. * @return the current non-null value */ public static HttpURLConnectionFactory get() { return RESOURCE; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy