in src/main/kotlin/org/jetbrains/teamcity/maven/sdk/Utils.kt [86:113]
public fun doDownloadTeamCity(): File {
val sourceURL = "$teamcitySourceURL/TeamCity-$teamcityVersion.tar.gz"
logInfo("Downloading TeamCity from $sourceURL")
val source = URL(sourceURL)
val sourceStream = source.openStream()
val downloadCounter = CountingInputStream(sourceStream)
val sourceChannel : ReadableByteChannel = Channels.newChannel(downloadCounter)!!
val tempFile = File.createTempFile("teamcityDistro", teamcityVersion)
val fos = FileOutputStream(tempFile);
val counterFlag : AtomicBoolean = AtomicBoolean(true)
val counter = createCounter(counterFlag, downloadCounter)
try {
counter.start()
logInfo("Transferring to temp file ${tempFile.absolutePath}")
fos.channel.transferFrom(sourceChannel, 0, java.lang.Long.MAX_VALUE);
} finally {
counterFlag.set(false)
counter.join(1000)
fos.close()
sourceChannel.close()
}
return tempFile
}