Source:
private void lookupOrDownload( final URI sourceFileUri, final File destinationFile ) throws DownloadException, IOException { final String uriString = sourceFileUri.toASCIIString(); log.debug("Lookup: {}", uriString); final String resourceCacheId = getResourceCacheId(sourceFileUri); final Resource resource; try { resource = resourceLoader.getResource(uriString); } catch (Throwable t) { log.error("Failed to retrieve resource: {}", uriString); throw t; } if (!resource.exists()) { throw new DownloadException("Resource not found: " + uriString); } final long resourceLastModified = resource.lastModified(); final File cacheResourceVersionDir = getCacheResourceVersionDir( resourceCacheId, resourceLastModified ); createDirectoryStructureIfNotExists(cacheResourceVersionDir); try ( CloseableLock lock = fileLockFactory.getLock( touchCacheResourceVersionLockFile( resourceCacheId, resourceLastModified ) ) ) { lock.lock(); final File cachedResourceVersionDataFile = getCacheResourceVersionDataFile( resourceCacheId, resourceLastModified ); if (!cachedResourceVersionDataFile.exists()) { log.debug( "Cache miss: (id: {})", uriString, resourceCacheId ); final File cachedResourceVersionDownloadFile = getCacheResourceVersionDownloadFile( resourceCacheId, resourceLastModified ); try ( InputStream in = resource.getInputStream(); OutputStream out = new FileOutputStream(cachedResourceVersionDownloadFile) ) { FileCopyUtils.copy(in, out); Files.move(cachedResourceVersionDownloadFile, cachedResourceVersionDataFile); } } else { log.debug( "Cache hit: (id: {})", uriString, resourceCacheId ); } Files.copy(cachedResourceVersionDataFile, destinationFile); } catch (LockException e) { throw new DownloadException("Error downloading dependency", e); } cleanUpTaskExecutor.execute( new CleanupOlderVersionsTask(resourceCacheId, resourceLastModified) ); }

Target:
private void lookupOrDownload( final URI sourceFileUri, final File destinationFile ) throws DownloadException, IOException { final String uriString = sourceFileUri.toASCIIString(); log.debug("Lookup: {}", uriString); final String resourceCacheId = getResourceCacheId(sourceFileUri); final Resource resource; try { resource = resourceLoader.getResource(uriString); } catch (Throwable t) { log.error( "Failed to retrieve resource: {}, - {}", uriString, t.getClass().getSimpleName(), t.getMessage() ); throw t; } if (!resource.exists()) { throw new DownloadException("Resource not found: " + uriString); } final long resourceLastModified = resource.lastModified(); final File cacheResourceVersionDir = getCacheResourceVersionDir( resourceCacheId, resourceLastModified ); createDirectoryStructureIfNotExists(cacheResourceVersionDir); try ( CloseableLock lock = fileLockFactory.getLock( touchCacheResourceVersionLockFile( resourceCacheId, resourceLastModified ) ) ) { lock.lock(); final File cachedResourceVersionDataFile = getCacheResourceVersionDataFile( resourceCacheId, resourceLastModified ); if (!cachedResourceVersionDataFile.exists()) { log.debug( "Cache miss: (id: {})", uriString, resourceCacheId ); final File cachedResourceVersionDownloadFile = getCacheResourceVersionDownloadFile( resourceCacheId, resourceLastModified ); try ( InputStream in = resource.getInputStream(); OutputStream out = new FileOutputStream(cachedResourceVersionDownloadFile) ) { FileCopyUtils.copy(in, out); Files.move(cachedResourceVersionDownloadFile, cachedResourceVersionDataFile); } } else { log.debug( "Cache hit: (id: {})", uriString, resourceCacheId ); } Files.copy(cachedResourceVersionDataFile, destinationFile); } catch (LockException e) { throw new DownloadException("Error downloading dependency", e); } cleanUpTaskExecutor.execute( new CleanupOlderVersionsTask(resourceCacheId, resourceLastModified) ); }