Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.github.jsonldjava.utils;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import org.apache.http.Header;
import org.apache.http.HttpVersion;
import org.apache.http.client.cache.HeaderConstants;
import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.client.cache.HttpCacheStorage;
import org.apache.http.client.cache.HttpCacheUpdateCallback;
import org.apache.http.client.cache.HttpCacheUpdateException;
import org.apache.http.client.cache.Resource;
import org.apache.http.client.utils.DateUtils;
import org.apache.http.impl.client.cache.BasicHttpCacheStorage;
import org.apache.http.impl.client.cache.CacheConfig;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicStatusLine;
import org.apache.http.protocol.HTTP;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.MapMaker;
/**
* Implementation of the Apache HttpClient {@link HttpCacheStorage} interface
* using {@code jarcache.json} files on the classpath to identify static JSON-LD
* resources on the classpath, to avoid retrieving them.
*
* @author Stian Soiland-Reyes
* @author Peter Ansell [email protected]
*/
public class JarCacheStorage implements HttpCacheStorage {
/**
* The classpath location that is searched inside of the classloader set for
* this cache. Note this search is also done on the Thread
* contextClassLoader if none is explicitly set, and the System classloader
* if there is no contextClassLoader.
*/
private static final String JARCACHE_JSON = "jarcache.json";
private final Logger log = LoggerFactory.getLogger(getClass());
private final CacheConfig cacheConfig;
/**
* The classloader to use, defaults to null which will use the thread
* context classloader.
*/
private ClassLoader classLoader = null;
/**
* A holder for the case where the System class loader needs to be used, but
* cannot be directly identified in another way.
*
* Used as a key in cachedResourceList.
*/
private static final Object NULL_CLASS_LOADER = new Object();
/**
* All live caching that is not found locally is delegated to this
* implementation.
*/
private final HttpCacheStorage delegate;
private final ObjectMapper mapper = new ObjectMapper();
/**
* Map from uri of jarcache.json (e.g. jar://blab.jar!jarcache.json) to a
* SoftReference to its parsed content as JsonNode.
*
* @see #getJarCache(URL)
*/
private final LoadingCache jarCaches = CacheBuilder.newBuilder()
.concurrencyLevel(4).maximumSize(100).softValues()
.build(new CacheLoader() {
@Override
public JsonNode load(URL url) throws IOException {
return mapper.readTree(url);
}
});
/**
* Cached URLs from the given ClassLoader to identified locations of
* jarcache.json resources on the classpath
*
* Uses a Guava concurrent weak reference key map to avoid holding onto
* ClassLoader instances after they are otherwise unavailable.
*/
private static final ConcurrentMap