in src/main/scala/org/intellij/scala/bundle/Mapper.scala [68:84]
def repack(name: String, compressionLevel: Int)(transfer: (Source, Destination) => Unit): Mapper = {
case entry =>
val sourceFile = File.createTempFile("repack", entry.name.replaceAll("\\\\|/", "-"))
using(new BufferedOutputStream(new FileOutputStream(sourceFile)))(IOUtils.copy(entry.input.get, _))
val destinationFile = File.createTempFile("repack", name.replaceAll("\\\\|/", "-"))
using(Destination(destinationFile, compressionLevel))(destination => using(Source(sourceFile))(transfer(_, destination)))
sourceFile.delete()
destinationFile.deleteOnExit()
entry.copy(
name = name,
size = destinationFile.length(),
input = Some(new BufferedInputStream(new FileInputStream(destinationFile))))
}