本文整理了Java中com.google.cloud.storage.Blob.delete()
方法的一些代码示例,展示了Blob.delete()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Blob.delete()
方法的具体详情如下:
包路径:com.google.cloud.storage.Blob
类名称:Blob
方法名:delete
[英]Deletes this blob.
Example of deleting the blob, if its generation matches the Blob#getGeneration()value, otherwise a StorageException is thrown.
boolean deleted = blob.delete(BlobSourceOption.generationMatch());else
// the blob was not found
}
}
[中]删除此blob。
删除blob的示例,如果其生成与blob#getGeneration()值匹配,则抛出StorageException。
boolean deleted = blob.delete(BlobSourceOption.generationMatch());else
// the blob was not found
}
}
代码示例来源:origin: googleapis/google-cloud-java
/**
* Example of deleting the blob, if its generation matches the {@link Blob#getGeneration()} value,
* otherwise a {@link StorageException} is thrown.
*/
// [TARGET delete(BlobSourceOption...)]
public boolean delete() {
// [START delete]
boolean deleted = blob.delete(BlobSourceOption.generationMatch());
if (deleted) {
// the blob was deleted
} else {
// the blob was not found
}
// [END delete]
return deleted;
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of moving a blob to a different bucket with a different name. */
// [TARGET copyTo(String, String, BlobSourceOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "move_blob_name"]
public Blob moveTo(String destBucket, String destBlob) {
// [START storageMoveFile]
CopyWriter copyWriter = blob.copyTo(destBucket, destBlob);
Blob copiedBlob = copyWriter.getResult();
boolean deleted = blob.delete();
// [END storageMoveFile]
if (deleted) {
return copiedBlob;
} else {
return null;
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testDelete() throws Exception {
initializeExpectedBlob(2);
expect(storage.getOptions()).andReturn(mockOptions);
expect(storage.delete(BLOB_INFO.getBlobId(), new Storage.BlobSourceOption[0])).andReturn(true);
replay(storage);
initializeBlob();
assertTrue(blob.delete());
}
代码示例来源:origin: googleapis/google-cloud-java
assertThat(storage.get(sourceBlob.getBlobId()).delete()).isTrue();
assertThat(storage.get(sourceBlob.getBlobId()).delete()).isTrue();
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testDeleteBlobFail() {
String blobName = "test-delete-blob-fail";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
Blob remoteBlob = storage.create(blob);
assertNotNull(remoteBlob);
try {
storage.delete(BUCKET, blob.getName(), Storage.BlobSourceOption.generationMatch(-1L));
fail("StorageException was expected");
} catch (StorageException ex) {
// expected
}
assertTrue(remoteBlob.delete());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testAttemptDeletionObjectTemporaryHold() {
String blobName = "test-create-with-temporary-hold";
BlobInfo blobInfo = BlobInfo.newBuilder(BUCKET, blobName).setTemporaryHold(true).build();
Blob remoteBlob = storage.create(blobInfo);
assertTrue(remoteBlob.getTemporaryHold());
try {
remoteBlob.delete();
fail("Expected failure on delete from temporaryHold");
} catch (StorageException ex) {
// expected
} finally {
remoteBlob.toBuilder().setEventBasedHold(false).build().update();
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testAttemptObjectDeleteWithEventBasedHold() {
String blobName = "test-create-with-event-based-hold";
BlobInfo blobInfo = BlobInfo.newBuilder(BUCKET, blobName).setEventBasedHold(true).build();
Blob remoteBlob = storage.create(blobInfo);
assertTrue(remoteBlob.getEventBasedHold());
try {
remoteBlob.delete();
fail("Expected failure on delete from eventBasedHold");
} catch (StorageException ex) {
// expected
} finally {
remoteBlob.toBuilder().setEventBasedHold(false).build().update();
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCreateBlob() {
String blobName = "test-create-blob";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
Blob remoteBlob = storage.create(blob, BLOB_BYTE_CONTENT);
assertNotNull(remoteBlob);
assertEquals(blob.getBucket(), remoteBlob.getBucket());
assertEquals(blob.getName(), remoteBlob.getName());
byte[] readBytes = storage.readAllBytes(BUCKET, blobName);
assertArrayEquals(BLOB_BYTE_CONTENT, readBytes);
assertTrue(remoteBlob.delete());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testAttemptObjectDeleteWithRetentionPolicy()
throws ExecutionException, InterruptedException {
String bucketName = RemoteStorageHelper.generateBucketName();
Bucket remoteBucket =
storage.create(
BucketInfo.newBuilder(bucketName).setRetentionPeriod(RETENTION_PERIOD).build());
assertEquals(RETENTION_PERIOD, remoteBucket.getRetentionPeriod());
String blobName = "test-create-with-retention-policy";
BlobInfo blobInfo = BlobInfo.newBuilder(bucketName, blobName).build();
Blob remoteBlob = storage.create(blobInfo);
assertNotNull(remoteBlob.getRetentionExpirationTime());
try {
remoteBlob.delete();
fail("Expected failure on delete from retentionPolicy");
} catch (StorageException ex) {
// expected
} finally {
Thread.sleep(RETENTION_PERIOD_IN_MILLISECONDS);
RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS);
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCopyBlobNoContentType() {
String sourceBlobName = "test-copy-blob-no-content-type-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
Blob remoteSourceBlob = storage.create(BlobInfo.newBuilder(source).build(), BLOB_BYTE_CONTENT);
assertNotNull(remoteSourceBlob);
String targetBlobName = "test-copy-blob-no-content-type-target";
ImmutableMap<String, String> metadata = ImmutableMap.of("k", "v");
BlobInfo target = BlobInfo.newBuilder(BUCKET, targetBlobName).setMetadata(metadata).build();
Storage.CopyRequest req = Storage.CopyRequest.of(source, target);
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertNull(copyWriter.getResult().getContentType());
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertTrue(copyWriter.isDone());
assertTrue(remoteSourceBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCopyBlob() {
String sourceBlobName = "test-copy-blob-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
ImmutableMap<String, String> metadata = ImmutableMap.of("k", "v");
BlobInfo blob =
BlobInfo.newBuilder(source).setContentType(CONTENT_TYPE).setMetadata(metadata).build();
Blob remoteBlob = storage.create(blob, BLOB_BYTE_CONTENT);
assertNotNull(remoteBlob);
String targetBlobName = "test-copy-blob-target";
Storage.CopyRequest req = Storage.CopyRequest.of(source, BlobId.of(BUCKET, targetBlobName));
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertTrue(copyWriter.isDone());
assertTrue(remoteBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCopyBlobUpdateMetadata() {
String sourceBlobName = "test-copy-blob-update-metadata-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
Blob remoteSourceBlob = storage.create(BlobInfo.newBuilder(source).build(), BLOB_BYTE_CONTENT);
assertNotNull(remoteSourceBlob);
String targetBlobName = "test-copy-blob-update-metadata-target";
ImmutableMap<String, String> metadata = ImmutableMap.of("k", "v");
BlobInfo target =
BlobInfo.newBuilder(BUCKET, targetBlobName)
.setContentType(CONTENT_TYPE)
.setMetadata(metadata)
.build();
Storage.CopyRequest req = Storage.CopyRequest.of(source, target);
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertTrue(copyWriter.isDone());
assertTrue(remoteSourceBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
}
代码示例来源:origin: googleapis/google-cloud-java
public void testCopyBlobUpdateStorageClass() {
String sourceBlobName = "test-copy-blob-update-storage-class-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
BlobInfo sourceInfo =
BlobInfo.newBuilder(source).setStorageClass(StorageClass.STANDARD).build();
Blob remoteSourceBlob = storage.create(sourceInfo, BLOB_BYTE_CONTENT);
assertNotNull(remoteSourceBlob);
assertEquals(StorageClass.STANDARD, remoteSourceBlob.getStorageClass());
String targetBlobName = "test-copy-blob-update-storage-class-target";
BlobInfo targetInfo =
BlobInfo.newBuilder(BUCKET, targetBlobName).setStorageClass(StorageClass.COLDLINE).build();
Storage.CopyRequest req = Storage.CopyRequest.of(source, targetInfo);
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(StorageClass.COLDLINE, copyWriter.getResult().getStorageClass());
assertTrue(copyWriter.isDone());
assertTrue(remoteSourceBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCopyBlobWithPredefinedAcl() {
String sourceBlobName = "test-copy-blob-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
ImmutableMap<String, String> metadata = ImmutableMap.of("k", "v");
BlobInfo blob =
BlobInfo.newBuilder(source).setContentType(CONTENT_TYPE).setMetadata(metadata).build();
Blob remoteBlob = storage.create(blob, BLOB_BYTE_CONTENT);
assertNotNull(remoteBlob);
String targetBlobName = "test-copy-blob-target";
Storage.CopyRequest req =
Storage.CopyRequest.newBuilder()
.setSource(source)
.setTarget(
BlobId.of(BUCKET, targetBlobName),
Storage.BlobTargetOption.predefinedAcl(Storage.PredefinedAcl.PUBLIC_READ))
.build();
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertNotNull(copyWriter.getResult().getAcl(User.ofAllUsers()));
assertTrue(copyWriter.isDone());
assertTrue(remoteBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
}
代码示例来源:origin: googleapis/google-cloud-java
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertTrue(copyWriter.isDone());
assertTrue(remoteBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
代码示例来源:origin: io.konig/konig-gcp-common
private void deleteBucket(Bucket bucket) {
if (bucket != null) {
Page<Blob> page = bucket.list();
for (Blob blob : page.iterateAll()) {
blob.delete();
}
bucket.delete();
}
}
代码示例来源:origin: ai.h2o/h2o-persist-gcs
@Override
public boolean delete(String path) {
final BlobId blob = GcsBlob.of(path).getBlobId();
keyCache.invalidate(blob.getBucket());
return storageProvider.getStorage().get(blob).delete();
}
代码示例来源:origin: ai.h2o/h2o-persist-gcs
@Override
public void delete(Value v) {
final BlobId blobId = GcsBlob.of(v._key).getBlobId();
Log.debug("Deleting: " + blobId.toString());
storageProvider.getStorage().get(blobId).delete();
}
内容来源于网络,如有侵权,请联系作者删除!