Search in sources :

Example 76 with Blob

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;
}
Also used : Blob(com.google.cloud.storage.Blob) CopyWriter(com.google.cloud.storage.CopyWriter)

Example 77 with Blob

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;
}
Also used : Blob(com.google.cloud.storage.Blob) CopyWriter(com.google.cloud.storage.CopyWriter)

Example 78 with Blob

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;
}
Also used : Blob(com.google.cloud.storage.Blob) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 79 with 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));
}
Also used : Blob(com.google.cloud.storage.Blob) Storage(com.google.cloud.storage.Storage) BlobInfo(com.google.cloud.storage.BlobInfo) BlobId(com.google.cloud.storage.BlobId)

Example 80 with Blob

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();
}
Also used : Blob(com.google.cloud.storage.Blob)

Aggregations

Blob (com.google.cloud.storage.Blob)80 BlobInfo (com.google.cloud.storage.BlobInfo)50 Test (org.junit.Test)50 BlobId (com.google.cloud.storage.BlobId)23 StorageException (com.google.cloud.storage.StorageException)16 Storage (com.google.cloud.storage.Storage)12 CopyWriter (com.google.cloud.storage.CopyWriter)10 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStream (java.io.InputStream)7 StorageBatch (com.google.cloud.storage.StorageBatch)4 URL (java.net.URL)4 URLConnection (java.net.URLConnection)4 ReadChannel (com.google.cloud.ReadChannel)3 Acl (com.google.cloud.storage.Acl)3 Bucket (com.google.cloud.storage.Bucket)3 CopyRequest (com.google.cloud.storage.Storage.CopyRequest)3 HashMap (java.util.HashMap)3 StorageBatchResult (com.google.cloud.storage.StorageBatchResult)2 FileInputStream (java.io.FileInputStream)2 ByteBuffer (java.nio.ByteBuffer)2