Created
March 20, 2019 05:13
-
-
Save int128/8fc4bdbb0e06794c0d9dd83b98070ec2 to your computer and use it in GitHub Desktop.
Create a ZIP/JAR file in Groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create a ZIP/JAR file with given contents. | |
* | |
* @param destination destination file | |
* @param contents map of filename and content | |
*/ | |
void createZIP(File destination, Map<String, String> contents) { | |
destination.withOutputStream { | |
new ZipOutputStream(it).withStream { zip -> | |
contents.each { filename, content -> | |
zip.putNextEntry(new ZipEntry(filename)) | |
zip << content | |
zip.closeEntry() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment