com.google.cloud.storage.Blob.getBlobId()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中com.google.cloud.storage.Blob.getBlobId()方法的一些代码示例,展示了Blob.getBlobId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Blob.getBlobId()方法的具体详情如下:
包路径:com.google.cloud.storage.Blob
类名称:Blob
方法名:getBlobId

Blob.getBlobId介绍

暂无

代码示例

代码示例来源:origin: googleapis/google-cloud-java

@Override
 public BlobId apply(Blob blob) {
  return blob.getBlobId();
 }
});

代码示例来源:origin: googleapis/google-cloud-java

@Override
 public BlobId apply(Blob blob) {
  return blob.getBlobId();
 }
});

代码示例来源:origin: googleapis/google-cloud-java

/**
 * Updates an ACL entry on this blob.
 *
 * <p>Example of updating a new ACL entry.
 *
 * <pre>{@code
 * Acl acl = blob.updateAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER));
 * }</pre>
 *
 * @throws StorageException upon failure
 */
public Acl updateAcl(Acl acl) {
 return storage.updateAcl(getBlobId(), acl);
}

代码示例来源:origin: googleapis/google-cloud-java

/**
 * Returns the ACL entry for the specified entity on this blob or {@code null} if not found.
 *
 * <p>Example of getting the ACL entry for an entity.
 *
 * <pre>{@code
 * Acl acl = blob.getAcl(User.ofAllAuthenticatedUsers());
 * }</pre>
 *
 * @throws StorageException upon failure
 */
public Acl getAcl(Entity entity) {
 return storage.getAcl(getBlobId(), entity);
}

代码示例来源:origin: googleapis/google-cloud-java

/**
 * Creates a new ACL entry on this blob.
 *
 * <p>Example of creating a new ACL entry.
 *
 * <pre>{@code
 * Acl acl = blob.createAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.READER));
 * }</pre>
 *
 * @throws StorageException upon failure
 */
public Acl createAcl(Acl acl) {
 return storage.createAcl(getBlobId(), acl);
}

代码示例来源:origin: googleapis/google-cloud-java

/**
 * Lists the ACL entries for this blob.
 *
 * <p>Example of listing the ACL entries.
 *
 * <pre>{@code
 * List<Acl> acls = blob.listAcls();
 * for (Acl acl : acls) {
 *   // do something with ACL entry
 * }
 * }</pre>
 *
 * @throws StorageException upon failure
 */
public List<Acl> listAcls() {
 return storage.listAcls(getBlobId());
}

代码示例来源:origin: googleapis/google-cloud-java

/**
 * Returns this blob's content.
 *
 * <p>Example of reading all bytes of the blob, if its generation matches the {@link
 * Blob#getGeneration()} value, otherwise a {@link StorageException} is thrown.
 *
 * <pre>{@code
 * byte[] content = blob.getContent(BlobSourceOption.generationMatch());
 * }</pre>
 *
 * @param options blob read options
 * @throws StorageException upon failure
 */
public byte[] getContent(BlobSourceOption... options) {
 return storage.readAllBytes(getBlobId(), toSourceOptions(this, options));
}

代码示例来源:origin: googleapis/google-cloud-java

/**
 * Fetches current blob's latest information. Returns {@code null} if the blob does not exist.
 *
 * <p>Example of getting the blob's latest information, if its generation does not match the
 * {@link Blob#getGeneration()} value, otherwise a {@link StorageException} is thrown.
 *
 * <pre>{@code
 * Blob latestBlob = blob.reload(BlobSourceOption.generationNotMatch());
 * if (latestBlob == null) {
 *   // the blob was not found
 * }
 * }</pre>
 *
 * @param options blob read options
 * @return a {@code Blob} object with latest information or {@code null} if not found
 * @throws StorageException upon failure
 */
public Blob reload(BlobSourceOption... options) {
 return storage.get(getBlobId(), toGetOptions(this, options));
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testForceDelete() throws InterruptedException, ExecutionException {
 Storage storageMock = EasyMock.createMock(Storage.class);
 EasyMock.expect(blob1.getBlobId()).andReturn(BLOB_ID1);
 EasyMock.expect(blob2.getBlobId()).andReturn(BLOB_ID2);
 ArrayList<BlobId> ids = new ArrayList<>();
 ids.add(BLOB_ID1);
 ids.add(BLOB_ID2);
 EasyMock.expect(storageMock.delete(ids)).andReturn(Collections.nCopies(2, true));
 EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true)))
   .andReturn(blobPage);
 EasyMock.expect(storageMock.delete(BUCKET_NAME)).andReturn(true);
 EasyMock.replay(storageMock, blob1, blob2);
 assertTrue(RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME, 5, TimeUnit.SECONDS));
 EasyMock.verify(storageMock, blob1, blob2);
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testForceDeleteNoTimeout() {
 Storage storageMock = EasyMock.createMock(Storage.class);
 EasyMock.expect(blob1.getBlobId()).andReturn(BLOB_ID1);
 EasyMock.expect(blob2.getBlobId()).andReturn(BLOB_ID2);
 ArrayList<BlobId> ids = new ArrayList<>();
 ids.add(BLOB_ID1);
 ids.add(BLOB_ID2);
 EasyMock.expect(storageMock.delete(ids)).andReturn(Collections.nCopies(2, true)).anyTimes();
 EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true)))
   .andReturn(blobPage);
 EasyMock.expect(storageMock.delete(BUCKET_NAME)).andReturn(true);
 EasyMock.replay(storageMock, blob1, blob2);
 RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME);
 EasyMock.verify(storageMock);
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testForceDeleteFail() throws InterruptedException, ExecutionException {
 Storage storageMock = EasyMock.createMock(Storage.class);
 EasyMock.expect(blob1.getBlobId()).andReturn(BLOB_ID1);
 EasyMock.expect(blob2.getBlobId()).andReturn(BLOB_ID2);
 ArrayList<BlobId> ids = new ArrayList<>();
 ids.add(BLOB_ID1);
 ids.add(BLOB_ID2);
 EasyMock.expect(storageMock.delete(ids)).andReturn(Collections.nCopies(2, true)).anyTimes();
 EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true)))
   .andReturn(blobPage);
 EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(FATAL_EXCEPTION);
 EasyMock.replay(storageMock, blob1, blob2);
 thrown.expect(ExecutionException.class);
 try {
  RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME, 5, TimeUnit.SECONDS);
 } finally {
  EasyMock.verify(storageMock);
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testForceDeleteTimeout() throws InterruptedException, ExecutionException {
 Storage storageMock = EasyMock.createMock(Storage.class);
 EasyMock.expect(blob1.getBlobId()).andReturn(BLOB_ID1).anyTimes();
 EasyMock.expect(blob2.getBlobId()).andReturn(BLOB_ID2).anyTimes();
 ArrayList<BlobId> ids = new ArrayList<>();
 ids.add(BLOB_ID1);
 ids.add(BLOB_ID2);
 EasyMock.expect(storageMock.delete(ids)).andReturn(Collections.nCopies(2, true)).anyTimes();
 EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true)))
   .andReturn(blobPage)
   .anyTimes();
 EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(RETRYABLE_EXCEPTION).anyTimes();
 EasyMock.replay(storageMock, blob1, blob2);
 assertFalse(
   RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME, 50, TimeUnit.MICROSECONDS));
 EasyMock.verify(storageMock);
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testExists_True() throws Exception {
 initializeExpectedBlob(1);
 Storage.BlobGetOption[] expectedOptions = {Storage.BlobGetOption.fields()};
 expect(storage.getOptions()).andReturn(mockOptions);
 expect(storage.get(expectedBlob.getBlobId(), expectedOptions)).andReturn(expectedBlob);
 replay(storage);
 initializeBlob();
 assertTrue(blob.exists());
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testCopyToBucket() throws Exception {
 initializeExpectedBlob(2);
 BlobInfo target = BlobInfo.newBuilder(BlobId.of("bt", "n")).build();
 CopyWriter copyWriter = createMock(CopyWriter.class);
 Capture<CopyRequest> capturedCopyRequest = Capture.newInstance();
 expect(storage.getOptions()).andReturn(mockOptions);
 expect(storage.copy(capture(capturedCopyRequest))).andReturn(copyWriter);
 replay(storage);
 initializeBlob();
 CopyWriter returnedCopyWriter = blob.copyTo("bt");
 assertEquals(copyWriter, returnedCopyWriter);
 assertEquals(capturedCopyRequest.getValue().getSource(), blob.getBlobId());
 assertEquals(capturedCopyRequest.getValue().getTarget(), target);
 assertFalse(capturedCopyRequest.getValue().overrideInfo());
 assertTrue(capturedCopyRequest.getValue().getSourceOptions().isEmpty());
 assertTrue(capturedCopyRequest.getValue().getTargetOptions().isEmpty());
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testCopyTo() throws Exception {
 initializeExpectedBlob(2);
 BlobInfo target = BlobInfo.newBuilder(BlobId.of("bt", "nt")).build();
 CopyWriter copyWriter = createMock(CopyWriter.class);
 Capture<CopyRequest> capturedCopyRequest = Capture.newInstance();
 expect(storage.getOptions()).andReturn(mockOptions);
 expect(storage.copy(capture(capturedCopyRequest))).andReturn(copyWriter);
 replay(storage);
 initializeBlob();
 CopyWriter returnedCopyWriter = blob.copyTo("bt", "nt");
 assertEquals(copyWriter, returnedCopyWriter);
 assertEquals(capturedCopyRequest.getValue().getSource(), blob.getBlobId());
 assertEquals(capturedCopyRequest.getValue().getTarget(), target);
 assertFalse(capturedCopyRequest.getValue().overrideInfo());
 assertTrue(capturedCopyRequest.getValue().getSourceOptions().isEmpty());
 assertTrue(capturedCopyRequest.getValue().getTargetOptions().isEmpty());
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testCopyToBlobId() throws Exception {
 initializeExpectedBlob(2);
 BlobInfo target = BlobInfo.newBuilder(BlobId.of("bt", "nt")).build();
 BlobId targetId = BlobId.of("bt", "nt");
 CopyWriter copyWriter = createMock(CopyWriter.class);
 Capture<CopyRequest> capturedCopyRequest = Capture.newInstance();
 expect(storage.getOptions()).andReturn(mockOptions);
 expect(storage.copy(capture(capturedCopyRequest))).andReturn(copyWriter);
 replay(storage);
 initializeBlob();
 CopyWriter returnedCopyWriter = blob.copyTo(targetId);
 assertEquals(copyWriter, returnedCopyWriter);
 assertEquals(capturedCopyRequest.getValue().getSource(), blob.getBlobId());
 assertEquals(capturedCopyRequest.getValue().getTarget(), target);
 assertFalse(capturedCopyRequest.getValue().overrideInfo());
 assertTrue(capturedCopyRequest.getValue().getSourceOptions().isEmpty());
 assertTrue(capturedCopyRequest.getValue().getTargetOptions().isEmpty());
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testGetBlobSelectedFields() {
 String blobName = "test-get-selected-fields-blob";
 BlobInfo blob =
   BlobInfo.newBuilder(BUCKET, blobName)
     .setContentType(CONTENT_TYPE)
     .setMetadata(ImmutableMap.of("k", "v"))
     .build();
 assertNotNull(storage.create(blob));
 Blob remoteBlob =
   storage.get(blob.getBlobId(), Storage.BlobGetOption.fields(BlobField.METADATA));
 assertEquals(blob.getBlobId(), remoteBlob.getBlobId());
 assertEquals(ImmutableMap.of("k", "v"), remoteBlob.getMetadata());
 assertNull(remoteBlob.getContentType());
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testGetBlobKmsKeyNameField() {
 String blobName = "test-get-selected-kms-key-name-field-blob";
 BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).setContentType(CONTENT_TYPE).build();
 assertNotNull(storage.create(blob, Storage.BlobTargetOption.kmsKeyName(kmsKeyOneResourcePath)));
 Blob remoteBlob =
   storage.get(blob.getBlobId(), Storage.BlobGetOption.fields(BlobField.KMS_KEY_NAME));
 assertEquals(blob.getBlobId(), remoteBlob.getBlobId());
 assertTrue(remoteBlob.getKmsKeyName().startsWith(kmsKeyOneResourcePath));
 assertNull(remoteBlob.getContentType());
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testGetBlobEmptySelectedFields() {
 String blobName = "test-get-empty-selected-fields-blob";
 BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).setContentType(CONTENT_TYPE).build();
 assertNotNull(storage.create(blob));
 Blob remoteBlob = storage.get(blob.getBlobId(), Storage.BlobGetOption.fields());
 assertEquals(blob.getBlobId(), remoteBlob.getBlobId());
 assertNull(remoteBlob.getContentType());
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testEnableDisableTemporaryHold() {
 String blobName = "test-create-with-temporary-hold";
 BlobInfo blobInfo = BlobInfo.newBuilder(BUCKET, blobName).setTemporaryHold(true).build();
 Blob remoteBlob = storage.create(blobInfo);
 assertTrue(remoteBlob.getTemporaryHold());
 remoteBlob =
   storage.get(remoteBlob.getBlobId(), Storage.BlobGetOption.fields(BlobField.TEMPORARY_HOLD));
 assertTrue(remoteBlob.getTemporaryHold());
 remoteBlob = remoteBlob.toBuilder().setTemporaryHold(false).build().update();
 assertFalse(remoteBlob.getTemporaryHold());
}

相关文章