@@ -21,10 +21,7 @@ import com.google.api.gax.retrying.RetrySettings
2121import com.google.auth.oauth2.GoogleCredentials
2222import com.google.cloud.ReadChannel
2323import com.google.cloud.http.HttpTransportOptions
24- import com.google.cloud.storage.BlobId
25- import com.google.cloud.storage.BlobInfo
26- import com.google.cloud.storage.StorageOptions
27- import com.google.cloud.storage.StorageRetryStrategy
24+ import com.google.cloud.storage.*
2825import org.gradle.api.GradleException
2926import org.gradle.api.logging.Logging
3027import java.io.InputStream
@@ -109,14 +106,22 @@ internal class GcpStorageService(
109106 private fun load (storage : StorageOptions ? , blobId : BlobId ): ReadChannel ? {
110107 if (storage == null ) return null
111108 val blob = storage.service.get(blobId) ? : return null
112- return blob.reader()
109+ val reader = blob.reader()
110+ // We don't expect to store objects larger than Int.MAX_VALUE
111+ reader.setChunkSize(blob.size.toInt())
112+ return reader
113113 }
114114
115115 private fun store (storage : StorageOptions ? , blobId : BlobId , contents : ByteArray ): Boolean {
116116 if (storage == null ) return false
117117 val blobInfo = BlobInfo .newBuilder(blobId).build()
118- storage.service.createFrom(blobInfo, contents.inputStream())
119- return true
118+ return try {
119+ storage.service.createFrom(blobInfo, contents.inputStream())
120+ true
121+ } catch (storageException: StorageException ) {
122+ logger.debug(" Unable to store Blob ($blobId )" , storageException)
123+ false
124+ }
120125 }
121126
122127 private fun delete (storage : StorageOptions ? , blobId : BlobId ): Boolean {
@@ -131,8 +136,8 @@ internal class GcpStorageService(
131136 ): StorageOptions ? {
132137 val credentials = credentials(gcpCredentials, isPushSupported) ? : return null
133138 val retrySettings = RetrySettings .newBuilder()
134- retrySettings.maxAttempts = 3
135- retrySettings.retryDelayMultiplier = 2. 0
139+ // We don't want retries.
140+ retrySettings.maxAttempts = 0
136141 return StorageOptions .newBuilder().setCredentials(credentials)
137142 .setStorageRetryStrategy(StorageRetryStrategy .getUniformStorageRetryStrategy()).setProjectId(projectId)
138143 .setRetrySettings(retrySettings.build())
0 commit comments