Skip to content
This repository was archived by the owner on Aug 19, 2020. It is now read-only.

Let Project scripts be cached in the Gradle build cache #978

Merged
merged 11 commits into from
Jul 20, 2018
Prev Previous commit
Ensure streams passed to build cache commands are closed
  • Loading branch information
bamboo committed Jul 20, 2018
commit 1c3001c28ecd0065a52de67443ff560ecc3e38e4
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ fun pack(inputDir: File, outputStream: OutputStream): Long {

var entryCount = 0L

val gzipOutputStream = GZIPOutputStream(outputStream)

DataOutputStream(gzipOutputStream).run {
DataOutputStream(GZIPOutputStream(outputStream)).useToRun {

val buffer = ByteArray(DEFAULT_BUFFER_SIZE)

Expand All @@ -58,16 +56,14 @@ fun pack(inputDir: File, outputStream: OutputStream): Long {
writeUTF("")
}

gzipOutputStream.finish()

return entryCount
}


internal
fun unpack(inputStream: InputStream, outputDir: File): Long =

DataInputStream(GZIPInputStream(inputStream)).run {
DataInputStream(GZIPInputStream(inputStream)).useToRun {

val buffer = ByteArray(DEFAULT_BUFFER_SIZE)

Expand Down Expand Up @@ -95,6 +91,11 @@ fun unpack(inputStream: InputStream, outputDir: File): Long =
}


private
inline fun <T : AutoCloseable, U> T.useToRun(action: T.() -> U): U =
use { run(action) }


private
fun File.copyTo(out: OutputStream, buffer: ByteArray) {
inputStream().use { input ->
Expand Down