/** * Convert an URL to a path on the local filesystem * * @param url * the url * @param copyIfNeeded * <code>true</code> if the url can not be converted to a local * the content is copied to the local filesystem * @return the path * @since 2.2.0 */ public static Optional<Resource<@NonNull Path>> getLocalPath(@NonNull URL url, boolean copyIfNeeded) { return lookupServiceList(URLResolver.class) .stream() .filter(r -> r.test(url)).findFirst() .map(r -> Optional.of(Resource.createResource(r.resolveToLocalPath(url)))) .orElseGet(() -> copyIfNeeded ? ExExecutor.executeSupplier( () -> Util.copyToTempFile(url), "Unable to copy resource") : Optional.empty()); //$NON-NLS-1$ }