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

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

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

Bucket.get介绍

[英]Returns a list of requested blobs in this bucket. Blobs that do not exist are null.

Example of getting some blobs in the bucket, using a batch request.

String blobName1 = "my_blob_name1";} 
}

[中]返回此bucket中请求的blob的列表。不存在的blob为null。
使用批处理请求在bucket中获取一些blob的示例。

String blobName1 = "my_blob_name1";} 
}

代码示例

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

/** Example of getting some blobs in the bucket, using a batch request. */
// [TARGET get(String, String, String...)]
// [VARIABLE "my_blob_name1"]
// [VARIABLE "my_blob_name2"]
public List<Blob> getBlobFromStrings(String blobName1, String blobName2) {
 // [START getBlobFromStrings]
 List<Blob> blobs = bucket.get(blobName1, blobName2);
 for (Blob blob : blobs) {
  if (blob == null) {
   // the blob was not found
  }
 }
 // [END getBlobFromStrings]
 return blobs;
}

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

@Test
public void testGet() throws Exception {
 initializeExpectedBucket(5);
 Blob expectedBlob =
   new Blob(
     serviceMockReturnsOptions,
     new BlobInfo.BuilderImpl(BlobInfo.newBuilder("b", "n").build()));
 expect(storage.getOptions()).andReturn(mockOptions);
 expect(storage.get(BlobId.of(expectedBucket.getName(), "n"), new Storage.BlobGetOption[0]))
   .andReturn(expectedBlob);
 replay(storage);
 initializeBucket();
 Blob blob = bucket.get("n");
 assertEquals(expectedBlob, blob);
}

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

/** Example of getting some blobs in the bucket, using a batch request. */
// [TARGET get(Iterable)]
// [VARIABLE "my_blob_name1"]
// [VARIABLE "my_blob_name2"]
public List<Blob> getBlobFromStringIterable(String blobName1, String blobName2) {
 // [START getBlobFromStringIterable]
 List<String> blobNames = new LinkedList<>();
 blobNames.add(blobName1);
 blobNames.add(blobName2);
 List<Blob> blobs = bucket.get(blobNames);
 for (Blob blob : blobs) {
  if (blob == null) {
   // the blob was not found
  }
 }
 // [END getBlobFromStringIterable]
 return blobs;
}

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

/**
 * Example of getting a blob in the bucket, only if its metageneration matches a value, otherwise
 * a {@link StorageException} is thrown.
 */
// [TARGET get(String, BlobGetOption...)]
// [VARIABLE "my_blob_name"]
// [VARIABLE 42]
public Blob getBlob(String blobName, long generation) {
 // [START getBlob]
 Blob blob = bucket.get(blobName, BlobGetOption.generationMatch(generation));
 // [END getBlob]
 return blob;
}

代码示例来源:origin: google/data-transfer-project

private byte[] getRawBytes(String blobName) {
 Bucket bucket = storage.get(bucketName);
 Preconditions.checkNotNull(bucket, "Bucket [%s] not found", bucketName);
 Blob blob = bucket.get(blobName);
 Preconditions.checkNotNull(blob, "blob [%s] not found", blobName);
 return blob.getContent();
}

代码示例来源:origin: google/data-transfer-project

InputStream getStream(UUID jobId, String keyName) {
 String blobName = getDataKeyName(jobId, keyName);
 Blob blob = bucket.get(blobName);
 ReadChannel channel = blob.reader();
 return Channels.newInputStream(channel);
}

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

@Test
public void testGetAllIterable() throws Exception {
 initializeExpectedBucket(4);
 expect(storage.getOptions()).andReturn(mockOptions);
 List<BlobId> blobIds =
   Lists.transform(
     blobResults,
     new Function<Blob, BlobId>() {
      @Override
      public BlobId apply(Blob blob) {
       return blob.getBlobId();
      }
     });
 expect(storage.get(blobIds)).andReturn(blobResults);
 replay(storage);
 initializeBucket();
 assertEquals(blobResults, bucket.get(ImmutableList.of("n1", "n2", "n3")));
}

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

@Test
public void testGetAllArray() throws Exception {
 initializeExpectedBucket(4);
 expect(storage.getOptions()).andReturn(mockOptions);
 List<BlobId> blobIds =
   Lists.transform(
     blobResults,
     new Function<Blob, BlobId>() {
      @Override
      public BlobId apply(Blob blob) {
       return blob.getBlobId();
      }
     });
 expect(storage.get(blobIds)).andReturn(blobResults);
 replay(storage);
 initializeBucket();
 assertEquals(blobResults, bucket.get("n1", "n2", "n3"));
}

相关文章