19
19
import static com .google .common .base .Preconditions .checkNotNull ;
20
20
21
21
import com .google .api .core .BetaApi ;
22
- import com .google .cloud .storage .Storage .BlobTargetOption ;
23
22
import com .google .cloud .storage .Storage .BlobWriteOption ;
24
23
import com .google .common .base .MoreObjects ;
25
24
import com .google .common .collect .ImmutableList ;
26
25
import java .util .List ;
27
26
import java .util .Objects ;
28
27
import org .checkerframework .checker .nullness .qual .NonNull ;
29
28
29
+ /**
30
+ * Configuration for performing Parallel Uploads with {@link TransferManager}.
31
+ *
32
+ * @see Builder
33
+ */
30
34
@ BetaApi
31
35
public final class ParallelUploadConfig {
32
36
33
37
private final boolean skipIfExists ;
34
38
@ NonNull private final String prefix ;
35
39
@ NonNull private final String bucketName ;
36
- @ NonNull private final List <BlobTargetOption > targetOptsPerRequest ;
37
40
38
41
@ NonNull private final List <BlobWriteOption > writeOptsPerRequest ;
39
42
40
43
private ParallelUploadConfig (
41
44
boolean skipIfExists ,
42
45
@ NonNull String prefix ,
43
46
@ NonNull String bucketName ,
44
- @ NonNull List <BlobTargetOption > targetOptsPerRequest ,
45
47
@ NonNull List <BlobWriteOption > writeOptsPerRequest ) {
46
48
this .skipIfExists = skipIfExists ;
47
49
this .prefix = prefix ;
48
50
this .bucketName = bucketName ;
49
- this .targetOptsPerRequest = targetOptsPerRequest ;
50
51
this .writeOptsPerRequest = applySkipIfExists (skipIfExists , writeOptsPerRequest );
51
52
}
52
53
53
- /** If a corresponding object already exists skip uploading the object */
54
+ /**
55
+ * If set Transfer Manager will skip uploading an object if it already exists, equivalent to
56
+ * providing {@link BlobWriteOption#doesNotExist()} in {@link #getWriteOptsPerRequest()}
57
+ *
58
+ * @see Builder#setSkipIfExists(boolean)
59
+ */
54
60
@ BetaApi
55
61
public boolean isSkipIfExists () {
56
62
return skipIfExists ;
57
63
}
58
64
59
- /** A common prefix that will be applied to all object paths in the destination bucket */
65
+ /**
66
+ * A common prefix that will be applied to all object paths in the destination bucket
67
+ *
68
+ * @see Builder#setPrefix(String)
69
+ */
60
70
@ BetaApi
61
71
public @ NonNull String getPrefix () {
62
72
return prefix ;
63
73
}
64
74
65
- /** The bucket objects are being uploaded from */
75
+ /**
76
+ * The bucket objects are being uploaded from
77
+ *
78
+ * @see Builder#setBucketName(String)
79
+ */
66
80
@ BetaApi
67
81
public @ NonNull String getBucketName () {
68
82
return bucketName ;
69
83
}
70
84
71
- /** A list of common BlobTargetOptions that are used for each upload request */
72
- @ BetaApi
73
- public @ NonNull List <BlobTargetOption > getTargetOptsPerRequest () {
74
- return targetOptsPerRequest ;
75
- }
76
-
77
- /** A list of common BlobWriteOptions that are used for each upload request */
85
+ /**
86
+ * A list of common BlobWriteOptions, note these options will be applied to each upload request.
87
+ *
88
+ * @see Builder#setWriteOptsPerRequest(List)
89
+ */
78
90
@ BetaApi
79
91
public @ NonNull List <BlobWriteOption > getWriteOptsPerRequest () {
80
92
return writeOptsPerRequest ;
@@ -92,12 +104,12 @@ public boolean equals(Object o) {
92
104
return skipIfExists == that .skipIfExists
93
105
&& prefix .equals (that .prefix )
94
106
&& bucketName .equals (that .bucketName )
95
- && targetOptsPerRequest .equals (that .targetOptsPerRequest );
107
+ && writeOptsPerRequest .equals (that .writeOptsPerRequest );
96
108
}
97
109
98
110
@ Override
99
111
public int hashCode () {
100
- return Objects .hash (skipIfExists , prefix , bucketName , targetOptsPerRequest );
112
+ return Objects .hash (skipIfExists , prefix , bucketName , writeOptsPerRequest );
101
113
}
102
114
103
115
@ Override
@@ -106,7 +118,7 @@ public String toString() {
106
118
.add ("skipIfExists" , skipIfExists )
107
119
.add ("prefix" , prefix )
108
120
.add ("bucketName" , bucketName )
109
- .add ("optionsPerRequest " , targetOptsPerRequest )
121
+ .add ("writeOptsPerRequest " , writeOptsPerRequest )
110
122
.toString ();
111
123
}
112
124
@@ -124,61 +136,86 @@ private static List<BlobWriteOption> applySkipIfExists(
124
136
return writeOptsPerRequest ;
125
137
}
126
138
139
+ /**
140
+ * Builds an instance of ParallelUploadConfig.
141
+ *
142
+ * @see ParallelUploadConfig
143
+ */
127
144
@ BetaApi
128
145
public static final class Builder {
129
146
130
147
private boolean skipIfExists ;
131
148
private @ NonNull String prefix ;
132
149
private @ NonNull String bucketName ;
133
- private @ NonNull List <BlobTargetOption > optionsPerRequest ;
134
-
135
150
private @ NonNull List <BlobWriteOption > writeOptsPerRequest ;
136
151
137
152
private Builder () {
138
153
this .prefix = "" ;
139
154
this .bucketName = "" ;
140
- this .optionsPerRequest = ImmutableList .of ();
141
155
this .writeOptsPerRequest = ImmutableList .of ();
142
156
}
143
157
158
+ /**
159
+ * Sets the parameter for skipIfExists. When set to true Transfer Manager will skip uploading an
160
+ * object if it already exists.
161
+ *
162
+ * @return the builder instance with the value for skipIfExists modified.
163
+ * @see ParallelUploadConfig#isSkipIfExists()
164
+ */
144
165
@ BetaApi
145
166
public Builder setSkipIfExists (boolean skipIfExists ) {
146
167
this .skipIfExists = skipIfExists ;
147
168
return this ;
148
169
}
149
170
171
+ /**
172
+ * Sets a common prefix that will be applied to all object paths in the destination bucket.
173
+ *
174
+ * @return the builder instance with the value for prefix modified.
175
+ * @see ParallelUploadConfig#getPrefix()
176
+ */
150
177
@ BetaApi
151
178
public Builder setPrefix (@ NonNull String prefix ) {
152
179
this .prefix = prefix ;
153
180
return this ;
154
181
}
155
182
183
+ /**
184
+ * Sets the bucketName that Transfer Manager will upload to. This field is required.
185
+ *
186
+ * @return the builder instance with the value for bucketName modified.
187
+ * @see ParallelUploadConfig#getBucketName()
188
+ */
156
189
@ BetaApi
157
190
public Builder setBucketName (@ NonNull String bucketName ) {
158
191
this .bucketName = bucketName ;
159
192
return this ;
160
193
}
161
194
162
- @ BetaApi
163
- public Builder setOptionsPerRequest (@ NonNull List <BlobTargetOption > optionsPerRequest ) {
164
- this .optionsPerRequest = ImmutableList .copyOf (optionsPerRequest );
165
- return this ;
166
- }
167
-
195
+ /**
196
+ * Sets the BlobWriteOptions that will be applied to each upload request. Note these options
197
+ * will be applied to every single upload request.
198
+ *
199
+ * @return the builder instance with the value for WriteOptsPerRequest modified.
200
+ * @see ParallelUploadConfig#getWriteOptsPerRequest()
201
+ */
168
202
@ BetaApi
169
203
public Builder setWriteOptsPerRequest (@ NonNull List <BlobWriteOption > writeOptsPerRequest ) {
170
204
this .writeOptsPerRequest = writeOptsPerRequest ;
171
205
return this ;
172
206
}
173
207
208
+ /**
209
+ * Creates a ParallelUploadConfig object.
210
+ *
211
+ * @return {@link ParallelUploadConfig}
212
+ */
174
213
@ BetaApi
175
214
public ParallelUploadConfig build () {
176
215
checkNotNull (prefix );
177
216
checkNotNull (bucketName );
178
- checkNotNull (optionsPerRequest );
179
217
checkNotNull (writeOptsPerRequest );
180
- return new ParallelUploadConfig (
181
- skipIfExists , prefix , bucketName , optionsPerRequest , writeOptsPerRequest );
218
+ return new ParallelUploadConfig (skipIfExists , prefix , bucketName , writeOptsPerRequest );
182
219
}
183
220
}
184
221
}
0 commit comments