Skip to content

Instantly share code, notes, and snippets.

@int128
Created March 20, 2019 05:13
Show Gist options
  • Save int128/8fc4bdbb0e06794c0d9dd83b98070ec2 to your computer and use it in GitHub Desktop.
Save int128/8fc4bdbb0e06794c0d9dd83b98070ec2 to your computer and use it in GitHub Desktop.
Create a ZIP/JAR file in Groovy
/**
* 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