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

ai.digital.integration.server.util.FileUtil.groovy Maven / Gradle / Ivy

The newest version!
package ai.digital.integration.server.util

import org.apache.commons.io.IOUtils

import java.nio.file.Path
import java.nio.file.Paths

class FileUtil {

    static def copyFile(InputStream source, Path dest) {
        def parentDir = dest.getParent().toFile()
        if (!parentDir.exists()) {
            parentDir.mkdirs()
        }
        def destFile = dest.toFile()
        destFile.createNewFile()
        def os = new FileOutputStream(destFile)

        try {
            IOUtils.copy(source, os)
        } finally {
            os.close()
        }
    }

    static def pathToString(Path path) {
        path.toAbsolutePath().toString()
    }

    static def toPathString(Path path, String subDir) {
        pathToString(Paths.get(pathToString(path), subDir))
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy