All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.deviniti.testflo.testsender.ZipFileCreator.kt Maven / Gradle / Ivy

There is a newer version: 1.0.11
Show newest version
package com.deviniti.testflo.testsender

import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream

fun createZipFile(inputFiles: List): File {
    val resultZipFile = File.createTempFile("test-results", ".zip")
    ZipOutputStream(FileOutputStream(resultZipFile)).use { resultZipFileOutputStream ->
        inputFiles.forEachIndexed { index, resultFile ->
            val zipEntry = ZipEntry("$index-${resultFile.name}")
            resultZipFileOutputStream.putNextEntry(zipEntry)
            FileInputStream(resultFile).use { resultFileInputStream ->
                resultFileInputStream.copyTo(resultZipFileOutputStream)
            }
        }
    }
    return resultZipFile
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy