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

me.saro.selenium.comm.Utils.kt Maven / Gradle / Ivy

There is a newer version: 4.26.0.0
Show newest version
package me.saro.selenium.comm

import java.io.File
import java.util.logging.Logger
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
import kotlin.reflect.KClass

class Utils {
    companion object {
        fun  getLogger(clazz: KClass): Logger = Logger.getLogger(clazz.java.name)

        fun unzip(zipFile: File, zipRootDepth: Int, destDir: File) =
            unzip(zipFile) {
                val paths = it.name.split("/")
                if (paths.size > zipRootDepth) {
                    File(destDir, paths.drop(zipRootDepth).joinToString("/"))
                } else null
            }

        fun unzip(zipFile: File, eachSavePath: (ZipEntry) -> File?) =
            ZipFile(zipFile).use { zip -> zip.entries().asSequence().forEach { entry ->
                eachSavePath(entry)?.also { file ->
                    if (entry.isDirectory) {
                        file.mkdirs()
                    } else {
                        file.parentFile.mkdirs()
                        file.outputStream().use { output -> zip.getInputStream(entry).copyTo(output) }
                    }
                }
            }}
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy