32
32
import java .util .concurrent .Callable ;
33
33
34
34
/**
35
- * Google Storage blob rewriter.
35
+ * Google Storage blob copy writer. This class holds the result of a copy request.
36
+ * If source and destination blobs do not share the same location or storage class more than one
37
+ * RPC request is needed to copy the blob. When this is the case {@link #copyChunk()} can be used
38
+ * to copy to destination other chunks of the source blob.
39
+ *
40
+ * @see <a href="https://cloud.google.com/storage/docs/json_api/v1/objects/rewrite">Rewrite</a>
36
41
*/
37
- public final class BlobRewriter implements Restorable <BlobRewriter > {
42
+ public class CopyWriter implements Restorable <CopyWriter > {
38
43
39
44
private final StorageOptions serviceOptions ;
40
45
private final StorageRpc storageRpc ;
41
46
private RewriteResponse rewriteResponse ;
42
47
43
- BlobRewriter (StorageOptions serviceOptions , RewriteResponse rewriteResponse ) {
48
+ CopyWriter (StorageOptions serviceOptions , RewriteResponse rewriteResponse ) {
44
49
this .serviceOptions = serviceOptions ;
45
50
this .rewriteResponse = rewriteResponse ;
46
51
this .storageRpc = serviceOptions .rpc ();
@@ -69,14 +74,14 @@ public Boolean isDone() {
69
74
}
70
75
71
76
/**
72
- * Returns the number of bytes written .
77
+ * Returns the number of bytes copied .
73
78
*/
74
- public Long totalBytesRewritten () {
79
+ public Long totalBytesCopied () {
75
80
return rewriteResponse .totalBytesRewritten ;
76
81
}
77
82
78
83
/**
79
- * Rewrite the next chunk of the blob. An RPC is issued only if rewrite has not finished yet
84
+ * Copies the next chunk of the blob. An RPC is issued only if copy has not finished yet
80
85
* ({@link #isDone} returns {@code false}).
81
86
*
82
87
* @throws StorageException upon failure
@@ -97,7 +102,7 @@ public RewriteResponse call() {
97
102
}
98
103
99
104
@ Override
100
- public RestorableState <BlobRewriter > capture () {
105
+ public RestorableState <CopyWriter > capture () {
101
106
return StateImpl .builder (
102
107
serviceOptions ,
103
108
BlobId .fromPb (rewriteResponse .rewriteRequest .source ),
@@ -108,11 +113,11 @@ public RestorableState<BlobRewriter> capture() {
108
113
.isDone (isDone ())
109
114
.megabytesRewrittenPerCall (rewriteResponse .rewriteRequest .megabytesRewrittenPerCall )
110
115
.rewriteToken (rewriteResponse .rewriteToken )
111
- .totalBytesRewritten (totalBytesRewritten ())
116
+ .totalBytesRewritten (totalBytesCopied ())
112
117
.build ();
113
118
}
114
119
115
- static class StateImpl implements RestorableState <BlobRewriter >, Serializable {
120
+ static class StateImpl implements RestorableState <CopyWriter >, Serializable {
116
121
117
122
private static final long serialVersionUID = 8279287678903181701L ;
118
123
@@ -125,7 +130,7 @@ static class StateImpl implements RestorableState<BlobRewriter>, Serializable {
125
130
private final Long blobSize ;
126
131
private final Boolean isDone ;
127
132
private final String rewriteToken ;
128
- private final Long totalBytesRewritten ;
133
+ private final Long totalBytesCopied ;
129
134
private final Long megabytesRewrittenPerCall ;
130
135
131
136
StateImpl (Builder builder ) {
@@ -138,7 +143,7 @@ static class StateImpl implements RestorableState<BlobRewriter>, Serializable {
138
143
this .blobSize = builder .blobSize ;
139
144
this .isDone = builder .isDone ;
140
145
this .rewriteToken = builder .rewriteToken ;
141
- this .totalBytesRewritten = builder .totalBytesRewritten ;
146
+ this .totalBytesCopied = builder .totalBytesCopied ;
142
147
this .megabytesRewrittenPerCall = builder .megabytesRewrittenPerCall ;
143
148
}
144
149
@@ -153,7 +158,7 @@ static class Builder {
153
158
private Long blobSize ;
154
159
private Boolean isDone ;
155
160
private String rewriteToken ;
156
- private Long totalBytesRewritten ;
161
+ private Long totalBytesCopied ;
157
162
private Long megabytesRewrittenPerCall ;
158
163
159
164
private Builder (StorageOptions options , BlobId source ,
@@ -187,7 +192,7 @@ Builder rewriteToken(String rewriteToken) {
187
192
}
188
193
189
194
Builder totalBytesRewritten (Long totalBytesRewritten ) {
190
- this .totalBytesRewritten = totalBytesRewritten ;
195
+ this .totalBytesCopied = totalBytesRewritten ;
191
196
return this ;
192
197
}
193
198
@@ -196,7 +201,7 @@ Builder megabytesRewrittenPerCall(Long megabytesRewrittenPerCall) {
196
201
return this ;
197
202
}
198
203
199
- RestorableState <BlobRewriter > build () {
204
+ RestorableState <CopyWriter > build () {
200
205
return new StateImpl (this );
201
206
}
202
207
}
@@ -208,19 +213,19 @@ static Builder builder(StorageOptions options, BlobId source,
208
213
}
209
214
210
215
@ Override
211
- public BlobRewriter restore () {
216
+ public CopyWriter restore () {
212
217
RewriteRequest rewriteRequest = new RewriteRequest (
213
218
source .toPb (), sourceOptions , target .toPb (), targetOptions , megabytesRewrittenPerCall );
214
219
RewriteResponse rewriteResponse = new RewriteResponse (rewriteRequest ,
215
220
result != null ? result .toPb () : null , blobSize , isDone , rewriteToken ,
216
- totalBytesRewritten );
217
- return new BlobRewriter (serviceOptions , rewriteResponse );
221
+ totalBytesCopied );
222
+ return new CopyWriter (serviceOptions , rewriteResponse );
218
223
}
219
224
220
225
@ Override
221
226
public int hashCode () {
222
227
return Objects .hash (serviceOptions , source , sourceOptions , target , targetOptions , result ,
223
- blobSize , isDone , megabytesRewrittenPerCall , rewriteToken , totalBytesRewritten );
228
+ blobSize , isDone , megabytesRewrittenPerCall , rewriteToken , totalBytesCopied );
224
229
}
225
230
226
231
@ Override
@@ -242,7 +247,7 @@ public boolean equals(Object obj) {
242
247
&& Objects .equals (this .blobSize , other .blobSize )
243
248
&& Objects .equals (this .isDone , other .isDone )
244
249
&& Objects .equals (this .megabytesRewrittenPerCall , other .megabytesRewrittenPerCall )
245
- && Objects .equals (this .totalBytesRewritten , other .totalBytesRewritten );
250
+ && Objects .equals (this .totalBytesCopied , other .totalBytesCopied );
246
251
}
247
252
248
253
@ Override
@@ -251,7 +256,7 @@ public String toString() {
251
256
.add ("source" , source )
252
257
.add ("target" , target )
253
258
.add ("isDone" , isDone )
254
- .add ("totalBytesRewritten" , totalBytesRewritten )
259
+ .add ("totalBytesRewritten" , totalBytesCopied )
255
260
.add ("blobSize" , blobSize )
256
261
.toString ();
257
262
}
0 commit comments