4343 * Implementation of the Apache HttpClient {@link HttpCacheStorage} interface
4444 * using {@code jarcache.json} files on the classpath to identify static JSON-LD
4545 * resources on the classpath, to avoid retrieving them.
46- *
46+ *
4747 * @author Stian Soiland-Reyes
4848 * @author Peter Ansell p_ansell@yahoo.com
4949 */
5050public class JarCacheStorage implements HttpCacheStorage {
5151
5252 /**
5353 * The classpath location that is searched inside of the classloader set for
54- * this cache. Note this search is also done on the Thread contextClassLoader if
55- * none is explicitly set, and the System classloader if there is no
56- * contextClassLoader.
54+ * this cache. Note this search is also done on the Thread
55+ * contextClassLoader if none is explicitly set, and the System classloader
56+ * if there is no contextClassLoader.
5757 */
5858 private static final String JARCACHE_JSON = "jarcache.json" ;
5959
@@ -62,15 +62,15 @@ public class JarCacheStorage implements HttpCacheStorage {
6262 private final CacheConfig cacheConfig ;
6363
6464 /**
65- * The classloader to use, defaults to null which will use the thread context
66- * classloader.
65+ * The classloader to use, defaults to null which will use the thread
66+ * context classloader.
6767 */
6868 private ClassLoader classLoader = null ;
6969
7070 /**
7171 * A holder for the case where the System class loader needs to be used, but
7272 * cannot be directly identified in another way.
73- *
73+ *
7474 * Used as a key in cachedResourceList.
7575 */
7676 private static final Object NULL_CLASS_LOADER = new Object ();
@@ -101,7 +101,7 @@ public JsonNode load(URL url) throws IOException {
101101 /**
102102 * Cached URLs from the given ClassLoader to identified locations of
103103 * jarcache.json resources on the classpath
104- *
104+ *
105105 * Uses a Guava concurrent weak reference key map to avoid holding onto
106106 * ClassLoader instances after they are otherwise unavailable.
107107 */
@@ -120,7 +120,7 @@ public JarCacheStorage(ClassLoader classLoader, CacheConfig cacheConfig,
120120 }
121121
122122 public ClassLoader getClassLoader () {
123- ClassLoader nextClassLoader = classLoader ;
123+ final ClassLoader nextClassLoader = classLoader ;
124124 if (nextClassLoader != null ) {
125125 return nextClassLoader ;
126126 }
@@ -129,9 +129,9 @@ public ClassLoader getClassLoader() {
129129
130130 /**
131131 * Sets the ClassLoader used internally to a new value, or null to use
132- * {@link Thread#currentThread()} and {@link Thread#getContextClassLoader()} for
133- * each access.
134- *
132+ * {@link Thread#currentThread()} and {@link Thread#getContextClassLoader()}
133+ * for each access.
134+ *
135135 * @param classLoader
136136 * The classloader to use, or null to use the thread context
137137 * classloader
@@ -168,16 +168,20 @@ public HttpCacheEntry getEntry(String key) throws IOException {
168168 log .trace ("Failed to normalise URI port before looking in cache: "
169169 + requestedUri , e );
170170 }
171- // Ignore syntax error and use the original URI directly instead
172- // This shouldn't happen as we already attempted to parse the URI earlier and
171+ // Ignore syntax error and use the original URI directly
172+ // instead
173+ // This shouldn't happen as we already attempted to parse
174+ // the URI earlier and
173175 // would not come here if that failed
174176 }
175177 }
176178
177- // getResources uses a cache to avoid scanning the classpath again for the
179+ // getResources uses a cache to avoid scanning the classpath again
180+ // for the
178181 // current classloader
179182 for (final URL url : getResources ()) {
180- // getJarCache attempts to use already parsed in-memory locations to avoid
183+ // getJarCache attempts to use already parsed in-memory
184+ // locations to avoid
181185 // retrieving and parsing again
182186 final JsonNode tree = getJarCache (url );
183187 for (final JsonNode node : tree ) {
@@ -194,9 +198,11 @@ public HttpCacheEntry getEntry(String key) throws IOException {
194198 }
195199
196200 /**
197- * Get all of the {@code jarcache.json} resources that exist on the classpath
198- *
199- * @return A cached list of jarcache.json classpath resources as {@link URL}s
201+ * Get all of the {@code jarcache.json} resources that exist on the
202+ * classpath
203+ *
204+ * @return A cached list of jarcache.json classpath resources as
205+ * {@link URL}s
200206 * @throws IOException
201207 * If there was an IO error while scanning the classpath
202208 */
@@ -207,7 +213,8 @@ private List<URL> getResources() throws IOException {
207213 // key
208214 final Object key = cl == null ? NULL_CLASS_LOADER : cl ;
209215
210- // computeIfAbsent requires unchecked exceptions for the creation process, so we
216+ // computeIfAbsent requires unchecked exceptions for the creation
217+ // process, so we
211218 // cannot easily use it directly, instead using get and putIfAbsent
212219 List <URL > newValue = cachedResourceList .get (key );
213220 if (newValue != null ) {
@@ -223,15 +230,16 @@ private List<URL> getResources() throws IOException {
223230 }
224231
225232 final List <URL > oldValue = cachedResourceList .putIfAbsent (key , newValue );
226- // We are not synchronising access to the ConcurrentMap, so if there were
233+ // We are not synchronising access to the ConcurrentMap, so if there
234+ // were
227235 // multiple classpath scans, we always choose the first one
228236 return oldValue != null ? oldValue : newValue ;
229237 }
230238
231239 protected JsonNode getJarCache (URL url ) throws IOException {
232240 try {
233241 return jarCaches .get (url );
234- } catch (ExecutionException e ) {
242+ } catch (final ExecutionException e ) {
235243 throw new IOException ("Failed to retrieve jar cache for URL: " + url , e );
236244 }
237245 }
0 commit comments