|
21 | 21 |
|
22 | 22 | import com.google.common.collect.ImmutableList; |
23 | 23 | import com.google.common.collect.Iterables; |
24 | | -import com.google.common.collect.Lists; |
25 | 24 | import com.google.gcloud.AuthCredentials.ServiceAccountAuthCredentials; |
26 | 25 | import com.google.gcloud.Service; |
27 | 26 | import com.google.gcloud.spi.StorageRpc; |
28 | | -import com.google.gcloud.spi.StorageRpc.Tuple; |
29 | 27 |
|
30 | 28 | import java.io.InputStream; |
31 | 29 | import java.io.Serializable; |
|
35 | 33 | import java.util.LinkedHashSet; |
36 | 34 | import java.util.LinkedList; |
37 | 35 | import java.util.List; |
38 | | -import java.util.Objects; |
39 | 36 | import java.util.Set; |
40 | 37 | import java.util.concurrent.TimeUnit; |
41 | 38 |
|
@@ -148,105 +145,6 @@ public static BlobTargetOption metagenerationMatch() { |
148 | 145 | public static BlobTargetOption metagenerationNotMatch() { |
149 | 146 | return new BlobTargetOption(StorageRpc.Option.IF_METAGENERATION_NOT_MATCH); |
150 | 147 | } |
151 | | - |
152 | | - static Tuple<BlobInfo, BlobTargetOption[]> convert(BlobInfo info, BlobWriteOption... options) { |
153 | | - BlobInfo.Builder infoBuilder = info.toBuilder().crc32c(null).md5(null); |
154 | | - List<BlobTargetOption> targetOptions = Lists.newArrayListWithCapacity(options.length); |
155 | | - for (BlobWriteOption option : options) { |
156 | | - switch (option.option) { |
157 | | - case IF_CRC32C_MATCH: |
158 | | - infoBuilder.crc32c(info.crc32c()); |
159 | | - break; |
160 | | - case IF_MD5_MATCH: |
161 | | - infoBuilder.md5(info.md5()); |
162 | | - break; |
163 | | - default: |
164 | | - targetOptions.add(option.toTargetOption()); |
165 | | - break; |
166 | | - } |
167 | | - } |
168 | | - return Tuple.of(infoBuilder.build(), |
169 | | - targetOptions.toArray(new BlobTargetOption[targetOptions.size()])); |
170 | | - } |
171 | | - } |
172 | | - |
173 | | - class BlobWriteOption implements Serializable { |
174 | | - |
175 | | - private static final long serialVersionUID = -3880421670966224580L; |
176 | | - |
177 | | - private final Option option; |
178 | | - private final Object value; |
179 | | - |
180 | | - enum Option { |
181 | | - PREDEFINED_ACL, IF_GENERATION_MATCH, IF_GENERATION_NOT_MATCH, IF_METAGENERATION_MATCH, |
182 | | - IF_METAGENERATION_NOT_MATCH, IF_MD5_MATCH, IF_CRC32C_MATCH; |
183 | | - |
184 | | - StorageRpc.Option toRpcOption() { |
185 | | - return StorageRpc.Option.valueOf(this.name()); |
186 | | - } |
187 | | - } |
188 | | - |
189 | | - BlobTargetOption toTargetOption() { |
190 | | - return new BlobTargetOption(this.option.toRpcOption(), this.value); |
191 | | - } |
192 | | - |
193 | | - private BlobWriteOption(Option option, Object value) { |
194 | | - this.option = option; |
195 | | - this.value = value; |
196 | | - } |
197 | | - |
198 | | - private BlobWriteOption(Option option) { |
199 | | - this(option, null); |
200 | | - } |
201 | | - |
202 | | - @Override |
203 | | - public int hashCode() { |
204 | | - return Objects.hash(option, value); |
205 | | - } |
206 | | - |
207 | | - @Override |
208 | | - public boolean equals(Object obj) { |
209 | | - if (obj == null) { |
210 | | - return false; |
211 | | - } |
212 | | - if (!(obj instanceof BlobWriteOption)) { |
213 | | - return false; |
214 | | - } |
215 | | - final BlobWriteOption other = (BlobWriteOption) obj; |
216 | | - return this.option == other.option && Objects.equals(this.value, other.value); |
217 | | - } |
218 | | - |
219 | | - public static BlobWriteOption predefinedAcl(PredefinedAcl acl) { |
220 | | - return new BlobWriteOption(Option.PREDEFINED_ACL, acl.entry()); |
221 | | - } |
222 | | - |
223 | | - public static BlobWriteOption doesNotExist() { |
224 | | - return new BlobWriteOption(Option.IF_GENERATION_MATCH, 0L); |
225 | | - } |
226 | | - |
227 | | - public static BlobWriteOption generationMatch() { |
228 | | - return new BlobWriteOption(Option.IF_GENERATION_MATCH); |
229 | | - } |
230 | | - |
231 | | - public static BlobWriteOption generationNotMatch() { |
232 | | - return new BlobWriteOption(Option.IF_GENERATION_NOT_MATCH); |
233 | | - } |
234 | | - |
235 | | - public static BlobWriteOption metagenerationMatch() { |
236 | | - return new BlobWriteOption(Option.IF_METAGENERATION_MATCH); |
237 | | - } |
238 | | - |
239 | | - public static BlobWriteOption metagenerationNotMatch() { |
240 | | - return new BlobWriteOption(Option.IF_METAGENERATION_NOT_MATCH); |
241 | | - } |
242 | | - |
243 | | - public static BlobWriteOption md5Match() { |
244 | | - return new BlobWriteOption(Option.IF_MD5_MATCH, true); |
245 | | - } |
246 | | - |
247 | | - public static BlobWriteOption crc32cMatch() { |
248 | | - return new BlobWriteOption(Option.IF_CRC32C_MATCH, true); |
249 | | - } |
250 | 148 | } |
251 | 149 |
|
252 | 150 | class BlobSourceOption extends Option { |
@@ -612,25 +510,21 @@ public static Builder builder() { |
612 | 510 |
|
613 | 511 | /** |
614 | 512 | * Create a new blob. Direct upload is used to upload {@code content}. For large content, |
615 | | - * {@link #writer} is recommended as it uses resumable upload. MD5 and CRC32C hashes of |
616 | | - * {@code content} are computed and used for validating transferred data. |
| 513 | + * {@link #writer} is recommended as it uses resumable upload. |
617 | 514 | * |
618 | 515 | * @return a complete blob information. |
619 | 516 | * @throws StorageException upon failure |
620 | | - * @see <a href="https://cloud.google.com/storage/docs/hashes-etags">Hashes and ETags</a> |
621 | 517 | */ |
622 | 518 | BlobInfo create(BlobInfo blobInfo, byte[] content, BlobTargetOption... options); |
623 | 519 |
|
624 | 520 | /** |
625 | 521 | * Create a new blob. Direct upload is used to upload {@code content}. For large content, |
626 | | - * {@link #writer} is recommended as it uses resumable upload. By default any md5 and crc32c |
627 | | - * values in the given {@code blobInfo} are ignored unless requested via the |
628 | | - * {@code BlobWriteOption.md5Match} and {@code BlobWriteOption.crc32cMatch} options. |
| 522 | + * {@link #writer} is recommended as it uses resumable upload. |
629 | 523 | * |
630 | 524 | * @return a complete blob information. |
631 | 525 | * @throws StorageException upon failure |
632 | 526 | */ |
633 | | - BlobInfo create(BlobInfo blobInfo, InputStream content, BlobWriteOption... options); |
| 527 | + BlobInfo create(BlobInfo blobInfo, InputStream content, BlobTargetOption... options); |
634 | 528 |
|
635 | 529 | /** |
636 | 530 | * Return the requested bucket or {@code null} if not found. |
@@ -785,13 +679,11 @@ public static Builder builder() { |
785 | 679 | BlobReadChannel reader(BlobId blob, BlobSourceOption... options); |
786 | 680 |
|
787 | 681 | /** |
788 | | - * Create a blob and return a channel for writing its content. By default any md5 and crc32c |
789 | | - * values in the given {@code blobInfo} are ignored unless requested via the |
790 | | - * {@code BlobWriteOption.md5Match} and {@code BlobWriteOption.crc32cMatch} options. |
| 682 | + * Create a blob and return a channel for writing its content. |
791 | 683 | * |
792 | 684 | * @throws StorageException upon failure |
793 | 685 | */ |
794 | | - BlobWriteChannel writer(BlobInfo blobInfo, BlobWriteOption... options); |
| 686 | + BlobWriteChannel writer(BlobInfo blobInfo, BlobTargetOption... options); |
795 | 687 |
|
796 | 688 | /** |
797 | 689 | * Generates a signed URL for a blob. |
|
0 commit comments