diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageWriterConfig.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfig.java similarity index 94% rename from google-cloud-storage/src/main/java/com/google/cloud/storage/StorageWriterConfig.java rename to google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfig.java index 7309f42e45..19c6086549 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageWriterConfig.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfig.java @@ -24,10 +24,10 @@ import java.io.IOException; import java.time.Clock; -public abstract class StorageWriterConfig { +public abstract class BlobWriteSessionConfig { @InternalApi - StorageWriterConfig() {} + BlobWriteSessionConfig() {} @InternalApi abstract WriterFactory createFactory(Clock clock) throws IOException; diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageWriterConfigs.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfigs.java similarity index 76% rename from google-cloud-storage/src/main/java/com/google/cloud/storage/StorageWriterConfigs.java rename to google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfigs.java index 39d01ab9b3..0faf6e69b9 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageWriterConfigs.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfigs.java @@ -19,12 +19,12 @@ import com.google.api.core.BetaApi; @BetaApi -public final class StorageWriterConfigs { +public final class BlobWriteSessionConfigs { - private StorageWriterConfigs() {} + private BlobWriteSessionConfigs() {} @BetaApi - public static DefaultStorageWriterConfig getDefault() { - return new DefaultStorageWriterConfig(ByteSizeConstants._16MiB); + public static DefaultBlobWriteSessionConfig getDefault() { + return new DefaultBlobWriteSessionConfig(ByteSizeConstants._16MiB); } } diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultStorageWriterConfig.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultBlobWriteSessionConfig.java similarity index 91% rename from google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultStorageWriterConfig.java rename to google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultBlobWriteSessionConfig.java index b5f74ef439..49427a9ef4 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultStorageWriterConfig.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultBlobWriteSessionConfig.java @@ -42,12 +42,12 @@ */ @Immutable @BetaApi -public final class DefaultStorageWriterConfig extends StorageWriterConfig { +public final class DefaultBlobWriteSessionConfig extends BlobWriteSessionConfig { private final int chunkSize; @InternalApi - DefaultStorageWriterConfig(int chunkSize) { + DefaultBlobWriteSessionConfig(int chunkSize) { this.chunkSize = chunkSize; } @@ -56,12 +56,12 @@ public int getChunkSize() { } @BetaApi - public DefaultStorageWriterConfig withChunkSize(int chunkSize) { + public DefaultBlobWriteSessionConfig withChunkSize(int chunkSize) { Preconditions.checkArgument( chunkSize >= ByteSizeConstants._256KiB, "chunkSize must be >= %d", ByteSizeConstants._256KiB); - return new DefaultStorageWriterConfig(chunkSize); + return new DefaultBlobWriteSessionConfig(chunkSize); } @Override @@ -96,7 +96,7 @@ public WritableByteChannelSession<?, BlobInfo> writeSession( writer.newLazyWriteChannel().getSession(); return new DecoratedWritableByteChannelSession<>(session, d); } - return CrossTransportUtils.throwGrpcOnly(DefaultStorageWriterConfig.class, ""); + return CrossTransportUtils.throwGrpcOnly(DefaultBlobWriteSessionConfig.class, ""); } } diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java index 6f26245d43..9f472f9183 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java @@ -46,6 +46,7 @@ import com.google.cloud.Policy; import com.google.cloud.WriteChannel; import com.google.cloud.storage.Acl.Entity; +import com.google.cloud.storage.BlobWriteSessionConfig.WriterFactory; import com.google.cloud.storage.BufferedWritableByteChannelSession.BufferedWritableByteChannel; import com.google.cloud.storage.Conversions.Decoder; import com.google.cloud.storage.HmacKey.HmacKeyMetadata; @@ -53,7 +54,6 @@ import com.google.cloud.storage.PostPolicyV4.PostConditionsV4; import com.google.cloud.storage.PostPolicyV4.PostFieldsV4; import com.google.cloud.storage.Storage.ComposeRequest.SourceBlob; -import com.google.cloud.storage.StorageWriterConfig.WriterFactory; import com.google.cloud.storage.UnbufferedReadableByteChannelSession.UnbufferedReadableByteChannel; import com.google.cloud.storage.UnbufferedWritableByteChannelSession.UnbufferedWritableByteChannel; import com.google.cloud.storage.UnifiedOpts.BucketListOpt; diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java index 1d6a432636..8728e59fec 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java @@ -83,7 +83,7 @@ public final class GrpcStorageOptions extends StorageOptions private final Duration terminationAwaitDuration; private final boolean attemptDirectPath; private final GrpcInterceptorProvider grpcInterceptorProvider; - private final StorageWriterConfig storageWriterConfig; + private final BlobWriteSessionConfig blobWriteSessionConfig; private GrpcStorageOptions(Builder builder, GrpcStorageDefaults serviceDefaults) { super(builder, serviceDefaults); @@ -96,7 +96,7 @@ private GrpcStorageOptions(Builder builder, GrpcStorageDefaults serviceDefaults) builder.terminationAwaitDuration, serviceDefaults.getTerminationAwaitDuration()); this.attemptDirectPath = builder.attemptDirectPath; this.grpcInterceptorProvider = builder.grpcInterceptorProvider; - this.storageWriterConfig = builder.storageWriterConfig; + this.blobWriteSessionConfig = builder.blobWriteSessionConfig; } @Override @@ -349,7 +349,7 @@ public static final class Builder extends StorageOptions.Builder { private boolean attemptDirectPath = GrpcStorageDefaults.INSTANCE.isAttemptDirectPath(); private GrpcInterceptorProvider grpcInterceptorProvider = GrpcStorageDefaults.INSTANCE.grpcInterceptorProvider(); - private StorageWriterConfig storageWriterConfig = + private BlobWriteSessionConfig blobWriteSessionConfig = GrpcStorageDefaults.INSTANCE.getDefaultStorageWriterConfig(); Builder() {} @@ -514,9 +514,9 @@ public GrpcStorageOptions.Builder setGrpcInterceptorProvider( /** @since 2.24.0 This new api is in preview and is subject to breaking changes. */ @BetaApi public GrpcStorageOptions.Builder setStorageWriterConfig( - @NonNull StorageWriterConfig storageWriterConfig) { - requireNonNull(storageWriterConfig, "storageWriterConfig must be non null"); - this.storageWriterConfig = storageWriterConfig; + @NonNull BlobWriteSessionConfig blobWriteSessionConfig) { + requireNonNull(blobWriteSessionConfig, "blobWriteSessionConfig must be non null"); + this.blobWriteSessionConfig = blobWriteSessionConfig; return this; } @@ -584,8 +584,8 @@ public GrpcInterceptorProvider grpcInterceptorProvider() { return INTERCEPTOR_PROVIDER; } - public StorageWriterConfig getDefaultStorageWriterConfig() { - return StorageWriterConfigs.getDefault(); + public BlobWriteSessionConfig getDefaultStorageWriterConfig() { + return BlobWriteSessionConfigs.getDefault(); } } @@ -638,7 +638,7 @@ public Storage create(StorageOptions options) { return new GrpcStorageImpl( grpcStorageOptions, StorageClient.create(storageSettings), - grpcStorageOptions.storageWriterConfig.createFactory(Clock.systemUTC()), + grpcStorageOptions.blobWriteSessionConfig.createFactory(Clock.systemUTC()), defaultOpts); } catch (IOException e) { throw new IllegalStateException( diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITBlobWriteSessionTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITBlobWriteSessionTest.java index 4a68cb3f23..986e5c85d6 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITBlobWriteSessionTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITBlobWriteSessionTest.java @@ -20,11 +20,12 @@ import com.google.cloud.storage.BlobInfo; import com.google.cloud.storage.BlobWriteSession; +import com.google.cloud.storage.BlobWriteSessionConfigs; import com.google.cloud.storage.BucketInfo; import com.google.cloud.storage.DataGenerator; import com.google.cloud.storage.GrpcStorageOptions; import com.google.cloud.storage.Storage; -import com.google.cloud.storage.StorageWriterConfigs; +import com.google.cloud.storage.Storage.BlobWriteOption; import com.google.cloud.storage.TransportCompatibility.Transport; import com.google.cloud.storage.it.runner.StorageITRunner; import com.google.cloud.storage.it.runner.annotations.Backend; @@ -60,7 +61,7 @@ public void overrideDefaultBufferSize() throws Exception { GrpcStorageOptions options = ((GrpcStorageOptions) storage.getOptions()) .toBuilder() - .setStorageWriterConfig(StorageWriterConfigs.getDefault().withChunkSize(256 * 1024)) + .setStorageWriterConfig(BlobWriteSessionConfigs.getDefault().withChunkSize(256 * 1024)) .build(); try (Storage s = options.getService()) { doTest(s); @@ -70,7 +71,8 @@ public void overrideDefaultBufferSize() throws Exception { private void doTest(Storage underTest) throws Exception { BlobWriteSession sess = underTest.blobWriteSession( - BlobInfo.newBuilder(bucket, generator.randomObjectName()).build()); + BlobInfo.newBuilder(bucket, generator.randomObjectName()).build(), + BlobWriteOption.doesNotExist()); byte[] bytes = DataGenerator.base64Characters().genBytes(512 * 1024); try (WritableByteChannel w = sess.open()) {