public static Resource exportClasspathResourceToFile(final File parentDirectory, final Resource resource) {
        LOGGER.trace("Preparing classpath resource [{}]", resource);
        if (resource == null) {
            LOGGER.warn("No resource defined to prepare.");
            return null;
        }
        if (!parentDirectory.exists() && !parentDirectory.mkdirs()) {
            LOGGER.warn("Unable to create folder [{}]", parentDirectory);
        }
        val destination = new File(parentDirectory, Objects.requireNonNull(resource.getFilename()));
        FunctionUtils.doUnchecked(__ -> {
            if (destination.exists()) {
                LOGGER.trace("Deleting resource directory [{}]", destination);
                FileUtils.forceDelete(destination);
            }
            try (val out = new FileOutputStream(destination);
                 val input = resource.getInputStream()) {
                input.transferTo(out);
            }
        });
        return new FileSystemResource(destination);
    }
Export classpath resource to file.

@param parentDirectory the parent directory
@param resource        the resource
@return the resource
core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/ResourceUtils.java