1717package com .google .cloud .storage ;
1818
1919import com .google .api .core .ApiFuture ;
20- import com .google .api .core .ApiFutures ;
2120import com .google .api .core .BetaApi ;
2221import com .google .api .core .InternalApi ;
2322import com .google .api .gax .grpc .GrpcCallContext ;
23+ import com .google .cloud .storage .DefaultBlobWriteSessionConfig .DecoratedWritableByteChannelSession ;
24+ import com .google .cloud .storage .DefaultBlobWriteSessionConfig .LazySession ;
25+ import com .google .cloud .storage .TransportCompatibility .Transport ;
2426import com .google .common .base .Preconditions ;
25- import com .google .common .util .concurrent .MoreExecutors ;
2627import com .google .storage .v2 .BidiWriteObjectRequest ;
2728import com .google .storage .v2 .BidiWriteObjectResponse ;
2829import java .io .IOException ;
29- import java .nio .channels .WritableByteChannel ;
3030import java .time .Clock ;
31+ import javax .annotation .concurrent .Immutable ;
3132
32- public class BidiBlobWriteSessionConfig extends BlobWriteSessionConfig
33+ /**
34+ * Perform a resumable upload, uploading at most {@code bufferSize} bytes each flush.
35+ *
36+ * <p>Configuration of buffer size can be performed via {@link
37+ * BidiBlobWriteSessionConfig#withBufferSize(int)}.
38+ *
39+ * @since 2.34.0 This new api is in preview and is subject to breaking changes.
40+ */
41+ @ Immutable
42+ @ BetaApi
43+ @ TransportCompatibility ({Transport .GRPC })
44+ public final class BidiBlobWriteSessionConfig extends BlobWriteSessionConfig
3345 implements BlobWriteSessionConfig .GrpcCompatible {
3446 private static final long serialVersionUID = -903533790705476197L ;
3547
@@ -54,7 +66,7 @@ public int getBufferSize() {
5466
5567 @ Override
5668 WriterFactory createFactory (Clock clock ) throws IOException {
57- return new Factory (ByteSizeConstants . _16MiB );
69+ return new Factory (bufferSize );
5870 }
5971
6072 @ InternalApi
@@ -124,57 +136,4 @@ public BidiBlobWriteSessionConfig withBufferSize(int bufferSize) {
124136 ByteSizeConstants ._256KiB );
125137 return new BidiBlobWriteSessionConfig (bufferSize );
126138 }
127-
128- private static final class DecoratedWritableByteChannelSession <WBC extends WritableByteChannel , T >
129- implements WritableByteChannelSession <WBC , BlobInfo > {
130-
131- private final WritableByteChannelSession <WBC , T > delegate ;
132- private final Conversions .Decoder <T , BlobInfo > decoder ;
133-
134- private DecoratedWritableByteChannelSession (
135- WritableByteChannelSession <WBC , T > delegate , Conversions .Decoder <T , BlobInfo > decoder ) {
136- this .delegate = delegate ;
137- this .decoder = decoder ;
138- }
139-
140- @ Override
141- public WBC open () {
142- try {
143- return WritableByteChannelSession .super .open ();
144- } catch (Exception e ) {
145- throw StorageException .coalesce (e );
146- }
147- }
148-
149- @ Override
150- public ApiFuture <WBC > openAsync () {
151- return delegate .openAsync ();
152- }
153-
154- @ Override
155- public ApiFuture <BlobInfo > getResult () {
156- return ApiFutures .transform (
157- delegate .getResult (), decoder ::decode , MoreExecutors .directExecutor ());
158- }
159- }
160-
161- private static final class LazySession <R >
162- implements WritableByteChannelSession <
163- BufferedWritableByteChannelSession .BufferedWritableByteChannel , R > {
164- private final LazyWriteChannel <R > lazy ;
165-
166- private LazySession (LazyWriteChannel <R > lazy ) {
167- this .lazy = lazy ;
168- }
169-
170- @ Override
171- public ApiFuture <BufferedWritableByteChannelSession .BufferedWritableByteChannel > openAsync () {
172- return lazy .getSession ().openAsync ();
173- }
174-
175- @ Override
176- public ApiFuture <R > getResult () {
177- return lazy .getSession ().getResult ();
178- }
179- }
180139}
0 commit comments