diff --git a/utils/ort/src/main/kotlin/storage/HttpFileStorage.kt b/utils/ort/src/main/kotlin/storage/HttpFileStorage.kt index 0e03034f93476..0cb0f87406396 100644 --- a/utils/ort/src/main/kotlin/storage/HttpFileStorage.kt +++ b/utils/ort/src/main/kotlin/storage/HttpFileStorage.kt @@ -80,10 +80,13 @@ class HttpFileStorage( } } - override fun exists(path: String): Boolean { - val request = Request.Builder() + private fun requestBuilder(): Request.Builder = + Request.Builder() .headers(headers.toHeaders()) .cacheControl(CacheControl.Builder().maxAge(cacheMaxAgeInSeconds, TimeUnit.SECONDS).build()) + + override fun exists(path: String): Boolean { + val request = requestBuilder() .head() .url(urlForPath(path)) .build() @@ -92,9 +95,7 @@ class HttpFileStorage( } override fun read(path: String): InputStream { - val request = Request.Builder() - .headers(headers.toHeaders()) - .cacheControl(CacheControl.Builder().maxAge(cacheMaxAgeInSeconds, TimeUnit.SECONDS).build()) + val request = requestBuilder() .get() .url(urlForPath(path)) .build() @@ -117,8 +118,7 @@ class HttpFileStorage( override fun write(path: String, inputStream: InputStream) { inputStream.use { - val request = Request.Builder() - .headers(headers.toHeaders()) + val request = requestBuilder() .put(it.readBytes().toRequestBody()) .url(urlForPath(path)) .build() diff --git a/utils/ort/src/main/kotlin/storage/S3FileStorage.kt b/utils/ort/src/main/kotlin/storage/S3FileStorage.kt index 4af5f5824cc3a..46860cf180263 100644 --- a/utils/ort/src/main/kotlin/storage/S3FileStorage.kt +++ b/utils/ort/src/main/kotlin/storage/S3FileStorage.kt @@ -72,11 +72,11 @@ class S3FileStorage( } if (awsRegion != null && provider != null) { - S3Client.builder().apply { - region(Region.of(awsRegion)) - credentialsProvider(provider) - endpointOverride(if (customEndpoint != null) URI.create(customEndpoint) else null) - }.build() + S3Client.builder() + .region(Region.of(awsRegion)) + .credentialsProvider(provider) + .endpointOverride(if (customEndpoint != null) URI.create(customEndpoint) else null) + .build() } else { if (awsRegion != null) { S3Client.builder().region(Region.of(awsRegion)).build() @@ -87,10 +87,10 @@ class S3FileStorage( } override fun exists(path: String): Boolean { - val request = HeadObjectRequest.builder().apply { - key(path) - bucket(bucketName) - }.build() + val request = HeadObjectRequest.builder() + .key(path) + .bucket(bucketName) + .build() return runCatching { s3Client.headObject(request) }.onFailure { exception -> if (exception !is NoSuchKeyException) { @@ -100,10 +100,10 @@ class S3FileStorage( } override fun read(path: String): InputStream { - val request = GetObjectRequest.builder().apply { - key(path) - bucket(bucketName) - }.build() + val request = GetObjectRequest.builder() + .key(path) + .bucket(bucketName) + .build() return runCatching { val response = s3Client.getObjectAsBytes(request) @@ -115,10 +115,10 @@ class S3FileStorage( } override fun write(path: String, inputStream: InputStream) { - val request = PutObjectRequest.builder().apply { - key(path) - bucket(bucketName) - }.build() + val request = PutObjectRequest.builder() + .key(path) + .bucket(bucketName) + .build() val body = inputStream.use { if (compression) {