32
32
import java .util .concurrent .Callable ;
33
33
34
34
/**
35
- * Google Storage blob copy writer. This class holds the result of a copy request. If source and
35
+ * Google Storage blob copy writer. A {@code CopyWriter} object allows to copy both blob's data and
36
+ * information. To override source blob's information supply a {@code BlobInfo} to the
37
+ * {@code CopyRequest} using either
38
+ * {@link Storage.CopyRequest.Builder#target(BlobInfo, Storage.BlobTargetOption...)} or
39
+ * {@link Storage.CopyRequest.Builder#target(BlobInfo, Iterable)}.
40
+ *
41
+ * <p>This class holds the result of a copy request. If source and
36
42
* destination blobs share the same location and storage class the copy is completed in one RPC call
37
43
* otherwise one or more {@link #copyChunk} calls are necessary to complete the copy. In addition,
38
44
* {@link CopyWriter#result()} can be used to automatically complete the copy and return information
@@ -65,11 +71,11 @@ public class CopyWriter implements Restorable<CopyWriter> {
65
71
*
66
72
* @throws StorageException upon failure
67
73
*/
68
- public BlobInfo result () {
74
+ public Blob result () {
69
75
while (!isDone ()) {
70
76
copyChunk ();
71
77
}
72
- return BlobInfo .fromPb (rewriteResponse .result );
78
+ return Blob .fromPb (serviceOptions . service (), rewriteResponse .result );
73
79
}
74
80
75
81
/**
@@ -120,8 +126,10 @@ public RestorableState<CopyWriter> capture() {
120
126
serviceOptions ,
121
127
BlobId .fromPb (rewriteResponse .rewriteRequest .source ),
122
128
rewriteResponse .rewriteRequest .sourceOptions ,
129
+ rewriteResponse .rewriteRequest .overrideInfo ,
123
130
BlobInfo .fromPb (rewriteResponse .rewriteRequest .target ),
124
131
rewriteResponse .rewriteRequest .targetOptions )
132
+ .result (rewriteResponse .result != null ? BlobInfo .fromPb (rewriteResponse .result ) : null )
125
133
.blobSize (blobSize ())
126
134
.isDone (isDone ())
127
135
.megabytesCopiedPerChunk (rewriteResponse .rewriteRequest .megabytesRewrittenPerCall )
@@ -132,11 +140,12 @@ public RestorableState<CopyWriter> capture() {
132
140
133
141
static class StateImpl implements RestorableState <CopyWriter >, Serializable {
134
142
135
- private static final long serialVersionUID = 8279287678903181701L ;
143
+ private static final long serialVersionUID = 1693964441435822700L ;
136
144
137
145
private final StorageOptions serviceOptions ;
138
146
private final BlobId source ;
139
147
private final Map <StorageRpc .Option , ?> sourceOptions ;
148
+ private final boolean overrideInfo ;
140
149
private final BlobInfo target ;
141
150
private final Map <StorageRpc .Option , ?> targetOptions ;
142
151
private final BlobInfo result ;
@@ -150,6 +159,7 @@ static class StateImpl implements RestorableState<CopyWriter>, Serializable {
150
159
this .serviceOptions = builder .serviceOptions ;
151
160
this .source = builder .source ;
152
161
this .sourceOptions = builder .sourceOptions ;
162
+ this .overrideInfo = builder .overrideInfo ;
153
163
this .target = builder .target ;
154
164
this .targetOptions = builder .targetOptions ;
155
165
this .result = builder .result ;
@@ -165,6 +175,7 @@ static class Builder {
165
175
private final StorageOptions serviceOptions ;
166
176
private final BlobId source ;
167
177
private final Map <StorageRpc .Option , ?> sourceOptions ;
178
+ private final boolean overrideInfo ;
168
179
private final BlobInfo target ;
169
180
private final Map <StorageRpc .Option , ?> targetOptions ;
170
181
private BlobInfo result ;
@@ -175,11 +186,12 @@ static class Builder {
175
186
private Long megabytesCopiedPerChunk ;
176
187
177
188
private Builder (StorageOptions options , BlobId source ,
178
- Map <StorageRpc .Option , ?> sourceOptions ,
179
- BlobInfo target , Map <StorageRpc .Option , ?> targetOptions ) {
189
+ Map <StorageRpc .Option , ?> sourceOptions , boolean overrideInfo , BlobInfo target ,
190
+ Map <StorageRpc .Option , ?> targetOptions ) {
180
191
this .serviceOptions = options ;
181
192
this .source = source ;
182
193
this .sourceOptions = sourceOptions ;
194
+ this .overrideInfo = overrideInfo ;
183
195
this .target = target ;
184
196
this .targetOptions = targetOptions ;
185
197
}
@@ -220,15 +232,15 @@ RestorableState<CopyWriter> build() {
220
232
}
221
233
222
234
static Builder builder (StorageOptions options , BlobId source ,
223
- Map <StorageRpc .Option , ?> sourceOptions , BlobInfo target ,
235
+ Map <StorageRpc .Option , ?> sourceOptions , boolean overrideInfo , BlobInfo target ,
224
236
Map <StorageRpc .Option , ?> targetOptions ) {
225
- return new Builder (options , source , sourceOptions , target , targetOptions );
237
+ return new Builder (options , source , sourceOptions , overrideInfo , target , targetOptions );
226
238
}
227
239
228
240
@ Override
229
241
public CopyWriter restore () {
230
- RewriteRequest rewriteRequest = new RewriteRequest (
231
- source . toPb (), sourceOptions , target .toPb (), targetOptions , megabytesCopiedPerChunk );
242
+ RewriteRequest rewriteRequest = new RewriteRequest (source . toPb (), sourceOptions ,
243
+ overrideInfo , target .toPb (), targetOptions , megabytesCopiedPerChunk );
232
244
RewriteResponse rewriteResponse = new RewriteResponse (rewriteRequest ,
233
245
result != null ? result .toPb () : null , blobSize , isDone , rewriteToken ,
234
246
totalBytesCopied );
@@ -237,8 +249,9 @@ public CopyWriter restore() {
237
249
238
250
@ Override
239
251
public int hashCode () {
240
- return Objects .hash (serviceOptions , source , sourceOptions , target , targetOptions , result ,
241
- blobSize , isDone , megabytesCopiedPerChunk , rewriteToken , totalBytesCopied );
252
+ return Objects .hash (serviceOptions , source , sourceOptions , overrideInfo , target ,
253
+ targetOptions , result , blobSize , isDone , megabytesCopiedPerChunk , rewriteToken ,
254
+ totalBytesCopied );
242
255
}
243
256
244
257
@ Override
@@ -253,6 +266,7 @@ public boolean equals(Object obj) {
253
266
return Objects .equals (this .serviceOptions , other .serviceOptions )
254
267
&& Objects .equals (this .source , other .source )
255
268
&& Objects .equals (this .sourceOptions , other .sourceOptions )
269
+ && Objects .equals (this .overrideInfo , other .overrideInfo )
256
270
&& Objects .equals (this .target , other .target )
257
271
&& Objects .equals (this .targetOptions , other .targetOptions )
258
272
&& Objects .equals (this .result , other .result )
@@ -267,10 +281,14 @@ public boolean equals(Object obj) {
267
281
public String toString () {
268
282
return MoreObjects .toStringHelper (this )
269
283
.add ("source" , source )
284
+ .add ("overrideInfo" , overrideInfo )
270
285
.add ("target" , target )
271
- .add ("isDone" , isDone )
272
- .add ("totalBytesRewritten" , totalBytesCopied )
286
+ .add ("result" , result )
273
287
.add ("blobSize" , blobSize )
288
+ .add ("isDone" , isDone )
289
+ .add ("rewriteToken" , rewriteToken )
290
+ .add ("totalBytesCopied" , totalBytesCopied )
291
+ .add ("megabytesCopiedPerChunk" , megabytesCopiedPerChunk )
274
292
.toString ();
275
293
}
276
294
}
0 commit comments