use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageSnippets method testComposeBlobs.
@Test
public void testComposeBlobs() {
String blobName = "my_blob_name";
String sourceBlobName1 = "source_blob_1";
String sourceBlobName2 = "source_blob_2";
BlobInfo blobInfo1 = BlobInfo.newBuilder(BUCKET, sourceBlobName1).build();
BlobInfo blobInfo2 = BlobInfo.newBuilder(BUCKET, sourceBlobName2).build();
storage.create(blobInfo1);
storage.create(blobInfo2);
assertNotNull(storageSnippets.composeBlobs(BUCKET, blobName, sourceBlobName1, sourceBlobName2));
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITBlobSnippets method testGetObjectMetadata.
@Test
public void testGetObjectMetadata() {
String blobName = "test-create-empty-blob";
BlobId blobId = BlobId.of(BUCKET, blobName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setMetadata(ImmutableMap.of("k", "v")).build();
Blob remoteBlob = storage.create(blobInfo, CONTENT);
assertNotNull(remoteBlob);
PrintStream systemOut = System.out;
final ByteArrayOutputStream snippetOutputCapture = new ByteArrayOutputStream();
System.setOut(new PrintStream(snippetOutputCapture));
GetObjectMetadata.getObjectMetadata(PROJECT_ID, BUCKET, blobName);
String snippetOutput = snippetOutputCapture.toString();
System.setOut(systemOut);
assertTrue(snippetOutput.contains("Bucket: " + remoteBlob.getBucket()));
assertTrue(snippetOutput.contains("Bucket: " + remoteBlob.getBucket()));
assertTrue(snippetOutput.contains("CacheControl: " + remoteBlob.getCacheControl()));
assertTrue(snippetOutput.contains("ComponentCount: " + remoteBlob.getComponentCount()));
assertTrue(snippetOutput.contains("ContentDisposition: " + remoteBlob.getContentDisposition()));
assertTrue(snippetOutput.contains("ContentEncoding: " + remoteBlob.getContentEncoding()));
assertTrue(snippetOutput.contains("ContentLanguage: " + remoteBlob.getContentLanguage()));
assertTrue(snippetOutput.contains("ContentType: " + remoteBlob.getContentType()));
assertTrue(snippetOutput.contains("CustomTime: " + remoteBlob.getCustomTime()));
assertTrue(snippetOutput.contains("Crc32c: " + remoteBlob.getCrc32c()));
assertTrue(snippetOutput.contains("Crc32cHexString: " + remoteBlob.getCrc32cToHexString()));
assertTrue(snippetOutput.contains("ETag: " + remoteBlob.getEtag()));
assertTrue(snippetOutput.contains("Generation: " + remoteBlob.getGeneration()));
assertTrue(snippetOutput.contains("Id: " + remoteBlob.getBlobId()));
assertTrue(snippetOutput.contains("KmsKeyName: " + remoteBlob.getKmsKeyName()));
assertTrue(snippetOutput.contains("Md5Hash: " + remoteBlob.getMd5()));
assertTrue(snippetOutput.contains("Md5HexString: " + remoteBlob.getMd5ToHexString()));
assertTrue(snippetOutput.contains("MediaLink: " + remoteBlob.getMediaLink()));
assertTrue(snippetOutput.contains("Metageneration: " + remoteBlob.getMetageneration()));
assertTrue(snippetOutput.contains("Name: " + remoteBlob.getName()));
assertTrue(snippetOutput.contains("Size: " + remoteBlob.getSize()));
assertTrue(snippetOutput.contains("StorageClass: " + remoteBlob.getStorageClass()));
assertTrue(snippetOutput.contains("TimeCreated: " + new Date(remoteBlob.getCreateTime())));
assertTrue(snippetOutput.contains("Last Metadata Update: " + new Date(remoteBlob.getUpdateTime())));
assertTrue(snippetOutput.contains("temporaryHold: disabled"));
assertTrue(snippetOutput.contains("eventBasedHold: disabled"));
assertTrue(snippetOutput.contains("User metadata:"));
assertTrue(snippetOutput.contains("k=v"));
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method writer.
/**
* Example of writing a blob's content through a writer.
*/
// [TARGET writer(BlobInfo, BlobWriteOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
public void writer(String bucketName, String blobName) throws IOException {
// [START writer]
BlobId blobId = BlobId.of(bucketName, blobName);
byte[] content = "Hello, World!".getBytes(UTF_8);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
try (WriteChannel writer = storage.writer(blobInfo)) {
try {
writer.write(ByteBuffer.wrap(content, 0, content.length));
} catch (Exception ex) {
// handle exception
}
}
// [END writer]
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method createBlob.
/**
* Example of creating a blob with no content.
*/
// [TARGET create(BlobInfo, BlobTargetOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
public Blob createBlob(String bucketName, String blobName) {
// [START createBlob]
BlobId blobId = BlobId.of(bucketName, blobName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
Blob blob = storage.create(blobInfo);
// [END createBlob]
return blob;
}
Aggregations