public static WritableResource toZipFile(final Stream<?> dataStream,
                                             final Function<Object, File> converter,
                                             final String prefix) {
        return Unchecked.supplier(() -> {
            val date = LocalDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm", Locale.ENGLISH));
            val file = Files.createTempFile(String.format("%s-%s", prefix, date), ".zip").toFile();
            Files.deleteIfExists(file.toPath());
            val env = new HashMap<String, Object>();
            env.put("create", "true");
            env.put("encoding", StandardCharsets.UTF_8.name());
            try (val zipfs = FileSystems.newFileSystem(URI.create("jar:" + file.toURI()), env)) {
                dataStream.forEach(Unchecked.consumer(entry -> {
                    var sourceFile = converter.apply(entry);
                    if (sourceFile.exists()) {
                        val pathInZipfile = zipfs.getPath("/".concat(sourceFile.getName()));
                        Files.copy(sourceFile.toPath(), pathInZipfile, StandardCopyOption.REPLACE_EXISTING);
                    }
                }));
            }
            return new TemporaryFileSystemResource(file);
        }).get();
    }
To zip file.

@param dataStream the data stream
@param converter  the converter
@param prefix     the prefix
@return the writable resource
core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/CompressionUtils.java