|
19 | 19 | import static com.google.common.base.MoreObjects.firstNonNull; |
20 | 20 |
|
21 | 21 | import com.google.api.services.storage.model.Bucket; |
22 | | -import com.google.api.services.storage.model.RewriteResponse; |
23 | 22 | import com.google.api.services.storage.model.StorageObject; |
24 | 23 | import com.google.common.collect.ImmutableList; |
25 | 24 | import com.google.common.collect.ImmutableMap; |
|
28 | 27 | import java.io.InputStream; |
29 | 28 | import java.util.List; |
30 | 29 | import java.util.Map; |
| 30 | +import java.util.Objects; |
31 | 31 |
|
32 | 32 | public interface StorageRpc { |
33 | 33 |
|
@@ -133,6 +133,89 @@ public BatchResponse(Map<StorageObject, Tuple<Boolean, StorageException>> delete |
133 | 133 | } |
134 | 134 | } |
135 | 135 |
|
| 136 | + class RewriteRequest { |
| 137 | + |
| 138 | + public final StorageObject source; |
| 139 | + public final Map<StorageRpc.Option, ?> sourceOptions; |
| 140 | + public final StorageObject target; |
| 141 | + public final Map<StorageRpc.Option, ?> targetOptions; |
| 142 | + public final Long megabytesRewrittenPerCall; |
| 143 | + |
| 144 | + public RewriteRequest(StorageObject source, Map<StorageRpc.Option, ?> sourceOptions, |
| 145 | + StorageObject target, Map<StorageRpc.Option, ?> targetOptions, |
| 146 | + Long megabytesRewrittenPerCall) { |
| 147 | + this.source = source; |
| 148 | + this.sourceOptions = sourceOptions; |
| 149 | + this.target = target; |
| 150 | + this.targetOptions = targetOptions; |
| 151 | + this.megabytesRewrittenPerCall = megabytesRewrittenPerCall; |
| 152 | + } |
| 153 | + |
| 154 | + @Override |
| 155 | + public boolean equals(Object obj) { |
| 156 | + if (obj == null) { |
| 157 | + return false; |
| 158 | + } |
| 159 | + if (!(obj instanceof RewriteRequest)) { |
| 160 | + return false; |
| 161 | + } |
| 162 | + final RewriteRequest other = (RewriteRequest) obj; |
| 163 | + return Objects.equals(this.source, other.source) |
| 164 | + && Objects.equals(this.sourceOptions, other.sourceOptions) |
| 165 | + && Objects.equals(this.target, other.target) |
| 166 | + && Objects.equals(this.targetOptions, other.targetOptions) |
| 167 | + && Objects.equals(this.megabytesRewrittenPerCall, other.megabytesRewrittenPerCall); |
| 168 | + } |
| 169 | + |
| 170 | + @Override |
| 171 | + public int hashCode() { |
| 172 | + return Objects.hash(source, sourceOptions, target, targetOptions, megabytesRewrittenPerCall); |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + class RewriteResponse { |
| 177 | + |
| 178 | + public final RewriteRequest rewriteRequest; |
| 179 | + public final StorageObject result; |
| 180 | + public final Long blobSize; |
| 181 | + public final Boolean isDone; |
| 182 | + public final String rewriteToken; |
| 183 | + public final Long totalBytesRewritten; |
| 184 | + |
| 185 | + public RewriteResponse(RewriteRequest rewriteRequest, StorageObject result, Long blobSize, |
| 186 | + Boolean isDone, String rewriteToken, Long totalBytesRewritten) { |
| 187 | + this.rewriteRequest = rewriteRequest; |
| 188 | + this.result = result; |
| 189 | + this.blobSize = blobSize; |
| 190 | + this.isDone = isDone; |
| 191 | + this.rewriteToken = rewriteToken; |
| 192 | + this.totalBytesRewritten = totalBytesRewritten; |
| 193 | + } |
| 194 | + |
| 195 | + @Override |
| 196 | + public boolean equals(Object obj) { |
| 197 | + if (obj == null) { |
| 198 | + return false; |
| 199 | + } |
| 200 | + if (!(obj instanceof RewriteResponse)) { |
| 201 | + return false; |
| 202 | + } |
| 203 | + final RewriteResponse other = (RewriteResponse) obj; |
| 204 | + return Objects.equals(this.rewriteRequest, other.rewriteRequest) |
| 205 | + && Objects.equals(this.result, other.result) |
| 206 | + && Objects.equals(this.rewriteToken, other.rewriteToken) |
| 207 | + && Objects.equals(this.blobSize, other.blobSize) |
| 208 | + && Objects.equals(this.isDone, other.isDone) |
| 209 | + && Objects.equals(this.totalBytesRewritten, other.totalBytesRewritten); |
| 210 | + } |
| 211 | + |
| 212 | + @Override |
| 213 | + public int hashCode() { |
| 214 | + return Objects.hash(rewriteRequest, result, blobSize, isDone, rewriteToken, |
| 215 | + totalBytesRewritten); |
| 216 | + } |
| 217 | + } |
| 218 | + |
136 | 219 | Bucket create(Bucket bucket, Map<Option, ?> options) throws StorageException; |
137 | 220 |
|
138 | 221 | StorageObject create(StorageObject object, InputStream content, Map<Option, ?> options) |
@@ -176,7 +259,7 @@ byte[] read(StorageObject from, Map<Option, ?> options, long position, int bytes |
176 | 259 | void write(String uploadId, byte[] toWrite, int toWriteOffset, StorageObject dest, |
177 | 260 | long destOffset, int length, boolean last) throws StorageException; |
178 | 261 |
|
179 | | - RewriteResponse rewrite(StorageObject source, Map<Option, ?> sourceOptions, |
180 | | - StorageObject target, Map<Option, ?> targetOptions, String token, Long maxByteRewrittenPerCall) |
181 | | - throws StorageException; |
| 262 | + RewriteResponse openRewrite(RewriteRequest rewriteRequest) throws StorageException; |
| 263 | + |
| 264 | + RewriteResponse continueRewrite(RewriteResponse previousResponse) throws StorageException; |
182 | 265 | } |
0 commit comments