diff --git a/build.gradle.kts b/build.gradle.kts index 7ad651c..652316f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -128,7 +128,7 @@ publishing { } tasks.withType { - gradleVersion = "8.0" + gradleVersion = "8.0.2" } java { diff --git a/src/main/kotlin/gay/pizza/foundation/concrete/ConcretePluginPlugin.kt b/src/main/kotlin/gay/pizza/foundation/concrete/ConcretePluginPlugin.kt index 9a0b661..277b7ff 100644 --- a/src/main/kotlin/gay/pizza/foundation/concrete/ConcretePluginPlugin.kt +++ b/src/main/kotlin/gay/pizza/foundation/concrete/ConcretePluginPlugin.kt @@ -1,7 +1,6 @@ package gay.pizza.foundation.concrete import org.gradle.api.Project -import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.get import org.gradle.language.jvm.tasks.ProcessResources diff --git a/src/main/kotlin/gay/pizza/foundation/concrete/SmartDownloader.kt b/src/main/kotlin/gay/pizza/foundation/concrete/SmartDownloader.kt index 8875d58..c579103 100644 --- a/src/main/kotlin/gay/pizza/foundation/concrete/SmartDownloader.kt +++ b/src/main/kotlin/gay/pizza/foundation/concrete/SmartDownloader.kt @@ -1,9 +1,13 @@ package gay.pizza.foundation.concrete import java.net.URI -import java.nio.file.Files +import java.net.http.HttpClient +import java.net.http.HttpRequest +import java.net.http.HttpResponse.BodyHandlers import java.nio.file.Path import java.security.MessageDigest +import kotlin.io.path.exists +import kotlin.io.path.inputStream class SmartDownloader( private val localFilePath: Path, @@ -20,23 +24,25 @@ class SmartDownloader( } private fun downloadRemoteFile() { - val url = remoteDownloadUrl.toURL() - val remoteFileStream = url.openStream() - val localFileStream = Files.newOutputStream(localFilePath) - remoteFileStream.transferTo(localFileStream) + val httpClient = HttpClient.newHttpClient() + val request = HttpRequest.newBuilder() + .GET() + .uri(remoteDownloadUrl) + .build() + httpClient.send(request, BodyHandlers.ofFile(localFilePath)) val hashResult = checkLocalFileHash() if (hashResult != HashResult.ValidHash) { - throw RuntimeException("Download of $remoteDownloadUrl did not result in valid hash.") + throw RuntimeException("Download of $remoteDownloadUrl did not result in a valid hash.") } } private fun checkLocalFileHash(): HashResult { - if (!Files.exists(localFilePath)) { + if (!localFilePath.exists()) { return HashResult.DoesNotExist } val digest = MessageDigest.getInstance("SHA-256") - val localFileStream = Files.newInputStream(localFilePath) + val localFileStream = localFilePath.inputStream() val buffer = ByteArray(16 * 1024) while (true) {