use of com.google.cloud.storage.Blob in project google-cloud-java by GoogleCloudPlatform.
the class BlobSnippets method copyToBucket.
/**
* 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;
}
use of com.google.cloud.storage.Blob in project google-cloud-java by GoogleCloudPlatform.
the class BlobSnippets method copyToStrings.
/**
* 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;
}
use of com.google.cloud.storage.Blob in project google-cloud-java by GoogleCloudPlatform.
the class BucketSnippets method createBlobFromInputStream.
/**
* Example of creating a blob in the bucket from an input stream.
*/
// [TARGET create(String, InputStream, BlobWriteOption...)]
// [VARIABLE "my_blob_name"]
public Blob createBlobFromInputStream(String blobName) {
// [START createBlobFromInputStream]
InputStream content = new ByteArrayInputStream("Hello, World!".getBytes(UTF_8));
Blob blob = bucket.create(blobName, content);
// [END createBlobFromInputStream]
return blob;
}
use of com.google.cloud.storage.Blob in project google-cloud-java by GoogleCloudPlatform.
the class CreateBlob method main.
public static void main(String... args) {
Storage storage = StorageOptions.getDefaultInstance().getService();
BlobId blobId = BlobId.of("bucket", "blob_name");
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
}
use of com.google.cloud.storage.Blob in project protoman by spotify.
the class GcsGenerationalFile method load.
public byte[] load() {
final Blob blob = storage.get(BlobId.of(bucket, path));
if (blob == null) {
throw new NotFoundException("File not found.");
}
generation = blob.getGeneration();
return blob.getContent();
}
Aggregations