本文整理了Java中com.google.cloud.storage.Blob.getContent()
方法的一些代码示例,展示了Blob.getContent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Blob.getContent()
方法的具体详情如下:
包路径:com.google.cloud.storage.Blob
类名称:Blob
方法名:getContent
[英]Returns this blob's content.
Example of reading all bytes of the blob, if its generation matches the Blob#getGeneration() value, otherwise a StorageException is thrown.
byte[] content = blob.getContent(BlobSourceOption.generationMatch());
[中]返回此blob的内容。
读取blob的所有字节的示例,如果其生成与blob#getGeneration()值匹配,则抛出StorageException。
byte[] content = blob.getContent(BlobSourceOption.generationMatch());
代码示例来源:origin: googleapis/google-cloud-java
/**
* Example of reading all bytes of the blob, if its generation matches the {@link
* Blob#getGeneration()} value, otherwise a {@link StorageException} is thrown.
*/
// [TARGET getContent(BlobSourceOption...)]
public byte[] getContent() {
// [START getContent]
byte[] content = blob.getContent(BlobSourceOption.generationMatch());
// [END getContent]
return content;
}
代码示例来源:origin: googleapis/google-cloud-java
assertNotNull(copyWriter.getResult().getKmsKeyName());
assertTrue(copyWriter.getResult().getKmsKeyName().startsWith(kmsKeyOneResourcePath));
assertArrayEquals(BLOB_BYTE_CONTENT, copyWriter.getResult().getContent());
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertTrue(copyWriter.isDone());
代码示例来源:origin: googleapis/google-cloud-java
assertArrayEquals(
BLOB_BYTE_CONTENT,
copyWriter.getResult().getContent(Blob.BlobSourceOption.decryptionKey(OTHER_BASE64_KEY)));
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertTrue(copyWriter.isDone());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertArrayEquals(BLOB_BYTE_CONTENT, copyWriter.getResult().getContent());
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertTrue(copyWriter.isDone());
代码示例来源: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: googleapis/google-cloud-java
public static void main(String... args) throws IOException {
Storage storage = StorageOptions.getDefaultInstance().getService();
BlobId blobId = BlobId.of("bucket", "blob_name");
Blob blob = storage.get(blobId);
if (blob != null) {
byte[] prevContent = blob.getContent();
System.out.println(new String(prevContent, UTF_8));
WritableByteChannel channel = blob.writer();
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
channel.close();
}
}
}
代码示例来源:origin: googleapis/google-cloud-java
public static void main(String... args) {
// Create a service object
// Credentials are inferred from the environment.
Storage storage = StorageOptions.getDefaultInstance().getService();
// Create a bucket
String bucketName = "my_unique_bucket"; // Change this to something unique
Bucket bucket = storage.create(BucketInfo.of(bucketName));
// Upload a blob to the newly created bucket
Blob blob = bucket.create("my_blob_name", "a simple blob".getBytes(UTF_8), "text/plain");
// Read the blob content from the server
String blobContent = new String(blob.getContent(), UTF_8);
// List all your buckets
System.out.println("My buckets:");
for (Bucket currentBucket : storage.list().iterateAll()) {
System.out.println(currentBucket);
}
// List the blobs in a particular bucket
System.out.println("My blobs:");
for (Blob currentBlob : bucket.list().iterateAll()) {
System.out.println(currentBlob);
}
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testContent() throws Exception {
initializeExpectedBlob(2);
byte[] content = {1, 2};
expect(storage.getOptions()).andReturn(mockOptions);
expect(storage.readAllBytes(BLOB_INFO.getBlobId())).andReturn(content);
replay(storage);
initializeBlob();
assertArrayEquals(content, blob.getContent());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testContentWithDecryptionKey() throws Exception {
initializeExpectedBlob(2);
byte[] content = {1, 2};
expect(storage.getOptions()).andReturn(mockOptions);
expect(
storage.readAllBytes(
BLOB_INFO.getBlobId(), Storage.BlobSourceOption.decryptionKey(BASE64_KEY)))
.andReturn(content)
.times(2);
replay(storage);
initializeBlob();
assertArrayEquals(content, blob.getContent(BlobSourceOption.decryptionKey(BASE64_KEY)));
assertArrayEquals(content, blob.getContent(BlobSourceOption.decryptionKey(KEY)));
}
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
String jsonContents = new String(firstOutputFile.getContent());
Builder builder = AnnotateFileResponse.newBuilder();
JsonFormat.parser().merge(jsonContents, builder);
内容来源于网络,如有侵权,请联系作者删除!