} catch (IOException e) {
throw new ResourceException(String.format("Failed to download resource '%s'.", resource.getName()), e);
}
return cacheLockingManager.useCache(String.format("Store %s", resource.getName()), new Factory<LocallyAvailableExternalResource>() {
public LocallyAvailableExternalResource create() {
LocallyAvailableResource cachedResource = fileStore.moveIntoCache(destination);
File fileInFileStore = cachedResource.getFile();
ExternalResourceMetaData metaData = resource.getMetaData();
cachedExternalResourceIndex.store(source.toString(), fileInFileStore, metaData);
return new DefaultLocallyAvailableExternalResource(source, cachedResource, metaData);
}
});