EasyMock.replay(storageRpcMock); initializeService(); Blob blob = storage.create(BLOB_INFO1, BLOB_CONTENT, BlobTargetOption.encryptionKey(KEY)); assertEquals(expectedBlob1, blob); ByteArrayInputStream byteStream = capturedStream.getValue(); assertArrayEquals(BLOB_CONTENT, streamBytes); assertEquals(-1, byteStream.read(streamBytes)); blob = storage.create(BLOB_INFO1, BLOB_CONTENT, BlobTargetOption.encryptionKey(BASE64_KEY)); assertEquals(expectedBlob1, blob); byteStream = capturedStream.getValue();
BlobInfo blob2 = BlobInfo.newBuilder(BUCKET, blobNames[1]).setContentType(CONTENT_TYPE).build(); Blob remoteBlob1 = storage.create(blob1, Storage.BlobTargetOption.kmsKeyName(kmsKeyOneResourcePath)); Blob remoteBlob2 = storage.create(blob2, Storage.BlobTargetOption.kmsKeyName(kmsKeyOneResourcePath)); assertNotNull(remoteBlob1); assertNotNull(remoteBlob2);
info, content, Storage.BlobTargetOption.generationMatch(), Storage.BlobTargetOption.metagenerationMatch(), Storage.BlobTargetOption.predefinedAcl(acl), Storage.BlobTargetOption.encryptionKey(BASE64_KEY), Storage.BlobTargetOption.userProject(USER_PROJECT))) .andReturn(expectedBlob); replay(storage);
copyReqBuilder = copyReqBuilder.setTarget(tgtInfo); } else { copyReqBuilder = copyReqBuilder.setTarget(tgtInfo, Storage.BlobTargetOption.doesNotExist());
case PREDEFINED_ACL: return Tuple.of( blobInfo, Storage.BlobTargetOption.predefinedAcl((Storage.PredefinedAcl) getValue())); case IF_GENERATION_MATCH: blobId = BlobId.of(blobId.getBucket(), blobId.getName(), (Long) getValue()); return Tuple.of( blobInfo.toBuilder().setBlobId(blobId).build(), Storage.BlobTargetOption.generationMatch()); case IF_GENERATION_NOT_MATCH: blobId = BlobId.of(blobId.getBucket(), blobId.getName(), (Long) getValue()); return Tuple.of( blobInfo.toBuilder().setBlobId(blobId).build(), Storage.BlobTargetOption.generationNotMatch()); case IF_METAGENERATION_MATCH: return Tuple.of( blobInfo.toBuilder().setMetageneration((Long) getValue()).build(), Storage.BlobTargetOption.metagenerationMatch()); case IF_METAGENERATION_NOT_MATCH: return Tuple.of( blobInfo.toBuilder().setMetageneration((Long) getValue()).build(), Storage.BlobTargetOption.metagenerationNotMatch()); case CUSTOMER_SUPPLIED_KEY: return Tuple.of(blobInfo, Storage.BlobTargetOption.encryptionKey((String) getValue())); case KMS_KEY_NAME: return Tuple.of(blobInfo, Storage.BlobTargetOption.kmsKeyName((String) getValue())); case USER_PROJECT: return Tuple.of(blobInfo, Storage.BlobTargetOption.userProject((String) getValue())); default: throw new AssertionError("Unexpected enum value");
BlobTargetOption toTargetOption() { return new BlobTargetOption(this.option.toRpcOption(), this.value); }
/** Returns an option to set a customer-managed key for server-side encryption of the blob. */ public static BlobTargetOption kmsKeyName(String kmsKeyName) { return new BlobTargetOption(StorageRpc.Option.KMS_KEY_NAME, kmsKeyName); }
/** Returns an option for specifying blob's predefined ACL configuration. */ public static BlobTargetOption predefinedAcl(PredefinedAcl acl) { return new BlobTargetOption(StorageRpc.Option.PREDEFINED_ACL, acl.getEntry()); }
/** * Returns an option for blob's billing user project. This option is only used by the buckets * with 'requester_pays' flag. */ public static BlobTargetOption userProject(String userProject) { return new BlobTargetOption(StorageRpc.Option.USER_PROJECT, userProject); }
/** * Returns an option that causes an operation to succeed only if the target blob does not exist. */ public static BlobTargetOption doesNotExist() { return new BlobTargetOption(StorageRpc.Option.IF_GENERATION_MATCH, 0L); }
@Override @Deprecated public Blob create(BlobInfo blobInfo, InputStream content, BlobWriteOption... options) { Tuple<BlobInfo, BlobTargetOption[]> targetOptions = BlobTargetOption.convert(blobInfo, options); StorageObject blobPb = targetOptions.x().toPb(); Map<StorageRpc.Option, ?> optionsMap = optionMap(targetOptions.x(), targetOptions.y()); InputStream inputStreamParam = firstNonNull(content, new ByteArrayInputStream(EMPTY_BYTE_ARRAY)); // retries are not safe when the input is an InputStream, so we can't retry. return Blob.fromPb(this, storageRpc.create(blobPb, inputStreamParam, optionsMap)); }
/** * Returns an option for blob's metageneration mismatch. If this option is used the request will * fail if metageneration matches. */ public static BlobTargetOption metagenerationNotMatch() { return new BlobTargetOption(StorageRpc.Option.IF_METAGENERATION_NOT_MATCH); }
/** * Returns an option for blob's data generation match. If this option is used the request will * fail if generation does not match. */ public static BlobTargetOption generationMatch() { return new BlobTargetOption(StorageRpc.Option.IF_GENERATION_MATCH); }
/** * Returns an option for blob's metageneration match. If this option is used the request will * fail if metageneration does not match. */ public static BlobTargetOption metagenerationMatch() { return new BlobTargetOption(StorageRpc.Option.IF_METAGENERATION_MATCH); }
/** * Returns an option for blob's data disabledGzipContent. If this option is used, the request * will create a blob with disableGzipContent; at present, this is only for upload. */ public static BlobTargetOption disableGzipContent() { return new BlobTargetOption(StorageRpc.Option.IF_DISABLE_GZIP_CONTENT, true); }
/** * Returns an option for blob's data generation mismatch. If this option is used the request * will fail if generation matches. */ public static BlobTargetOption generationNotMatch() { return new BlobTargetOption(StorageRpc.Option.IF_GENERATION_NOT_MATCH); }
/** * Returns an option to set a customer-supplied AES256 key for server-side encryption of the * blob. * * @param key the AES256 encoded in base64 */ public static BlobTargetOption encryptionKey(String key) { return new BlobTargetOption(StorageRpc.Option.CUSTOMER_SUPPLIED_KEY, key); }
/** * Returns an option to set a customer-supplied AES256 key for server-side encryption of the * blob. */ public static BlobTargetOption encryptionKey(Key key) { String base64Key = BaseEncoding.base64().encode(key.getEncoded()); return new BlobTargetOption(StorageRpc.Option.CUSTOMER_SUPPLIED_KEY, base64Key); }
@Override public BlobWriteChannel writer(BlobInfo blobInfo, BlobWriteOption... options) { Tuple<BlobInfo, BlobTargetOption[]> targetOptions = BlobTargetOption.convert(blobInfo, options); return writer(targetOptions.x(), targetOptions.y()); }
} else { copyReqBuilder = copyReqBuilder.setTarget(tgtInfo, Storage.BlobTargetOption.doesNotExist());