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

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

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

Blob.copyTo介绍

[英]Sends a copy request for the current blob to the target blob. Possibly also some of the metadata are copied (e.g. content-type).

Example of copying the blob to a different bucket with a different name.

String bucketName = "my_unique_bucket";

[中]向目标blob发送当前blob的复制请求。可能还会复制一些元数据(例如,内容类型)。
将blob复制到具有不同名称的不同bucket的示例。

String bucketName = "my_unique_bucket";

代码示例

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

/** Example of copying the blob to a different bucket, keeping the original name. */
// [TARGET copyTo(String, BlobSourceOption...)]
// [VARIABLE "my_unique_bucket"]
public Blob copyToBucket(String bucketName) {
 // [START copyToBucket]
 CopyWriter copyWriter = blob.copyTo(bucketName);
 Blob copiedBlob = copyWriter.getResult();
 // [END copyToBucket]
 return copiedBlob;
}

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

/** Example of copying the blob to a different bucket with a different name. */
// [TARGET copyTo(String, String, BlobSourceOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "copy_blob_name"]
public Blob copyToStrings(String bucketName, String blobName) {
 // [START copyToStrings]
 CopyWriter copyWriter = blob.copyTo(bucketName, blobName);
 Blob copiedBlob = copyWriter.getResult();
 // [END copyToStrings]
 return copiedBlob;
}

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

/**
 * Sends a copy request for the current blob to the target bucket, preserving its name. Possibly
 * copying also some of the metadata (e.g. content-type).
 *
 * <p>Example of copying the blob to a different bucket, keeping the original name.
 *
 * <pre>{@code
 * String bucketName = "my_unique_bucket";
 * CopyWriter copyWriter = blob.copyTo(bucketName);
 * Blob copiedBlob = copyWriter.getResult();
 * }</pre>
 *
 * @param targetBucket target bucket's name
 * @param options source blob options
 * @return a {@link CopyWriter} object that can be used to get information on the newly created
 *     blob or to complete the copy if more than one RPC request is needed
 * @throws StorageException upon failure
 */
public CopyWriter copyTo(String targetBucket, BlobSourceOption... options) {
 return copyTo(targetBucket, getName(), options);
}

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

return copyTo(BlobId.of(targetBucket, targetBlob), options);

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

/** Example of copying the blob to a different bucket with a different name. */
// [TARGET copyTo(BlobId, BlobSourceOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "copy_blob_name"]
public Blob copyToId(String bucketName, String blobName) {
 // [START copyToId]
 CopyWriter copyWriter = blob.copyTo(BlobId.of(bucketName, blobName));
 Blob copiedBlob = copyWriter.getResult();
 // [END copyToId]
 return copiedBlob;
}

代码示例来源: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 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: com.google.cloud/google-cloud-storage

/**
 * Sends a copy request for the current blob to the target bucket, preserving its name. Possibly
 * copying also some of the metadata (e.g. content-type).
 *
 * <p>Example of copying the blob to a different bucket, keeping the original name.
 *
 * <pre>{@code
 * String bucketName = "my_unique_bucket";
 * CopyWriter copyWriter = blob.copyTo(bucketName);
 * Blob copiedBlob = copyWriter.getResult();
 * }</pre>
 *
 * @param targetBucket target bucket's name
 * @param options source blob options
 * @return a {@link CopyWriter} object that can be used to get information on the newly created
 *     blob or to complete the copy if more than one RPC request is needed
 * @throws StorageException upon failure
 */
public CopyWriter copyTo(String targetBucket, BlobSourceOption... options) {
 return copyTo(targetBucket, getName(), options);
}

代码示例来源:origin: com.google.cloud/google-cloud-storage

return copyTo(BlobId.of(targetBucket, targetBlob), options);

代码示例来源:origin: ai.h2o/h2o-persist-gcs

@Override
public boolean rename(String fromPath, String toPath) {
 final BlobId fromBlob = GcsBlob.of(fromPath).getBlobId();
 final BlobId toBlob = GcsBlob.of(toPath).getBlobId();
 storageProvider.getStorage().get(fromBlob).copyTo(toBlob);
 keyCache.invalidate(fromBlob.getBucket());
 keyCache.invalidate(toBlob.getBucket());
 return storageProvider.getStorage().delete(fromBlob);
}

相关文章