1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Template work.

This commit is contained in:
Cedric Beust 2016-02-23 22:36:52 +04:00
parent 5bcd611c99
commit e760439373
7 changed files with 98 additions and 23 deletions

View file

@ -1,6 +1,7 @@
package com.beust.kobalt.api
import com.beust.kobalt.Args
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import java.io.File
import java.io.FileOutputStream
@ -23,11 +24,7 @@ abstract class JarTemplate(val jarName: String) : ITemplate {
log(2, "Extracting: $entry to ${f.absolutePath}")
FileOutputStream(f).use { fos ->
var read = ins.read()
while (ins.available() > 0 && read != -1) {
fos.write(read)
read = ins.read()
}
KFiles.copy(ins, fos)
}
entry = ins.nextEntry
}

View file

@ -7,6 +7,8 @@ import com.beust.kobalt.internal.build.BuildFile
import com.beust.kobalt.maven.Md5
import java.io.File
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
@ -261,6 +263,14 @@ class KFiles {
}
}
fun copy(from: InputStream, to: OutputStream) {
var read = from.read()
while (from.available() > 0 && read != -1) {
to.write(read)
read = from.read()
}
}
fun createTempFile(suffix : String = "", deleteOnExit: Boolean = false) : File =
File.createTempFile("kobalt", suffix, File(SystemProperties.tmpDir)).let {
if (deleteOnExit) it.deleteOnExit()