All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.cloud.storage.package-info Maven / Gradle / Ivy

There is a newer version: 2.45.0
Show newest version
/*
 * Copyright 2015 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * A client for Cloud Storage - Unified object storage.
 *
 * 

Here's a simple usage example the Java Storage client. This example shows how to create a * Storage object. * *

{@code
 * 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));
 * }
* *

This second example shows how to update an object's content if the object exists. * *

{@code
 * 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();
 * }
 * }
* *

For more detailed code examples, see the sample library. * *

When using google-cloud from outside of App/Compute Engine, you have to specify a project * ID and provide * credentials. * *

Operations in this library are generally thread safe, except for the use of * BlobReadChannel and * BlobWriteChannel. * *

The GCS Java client library includes support to GCS via gRPC. When using GCS from Google * Compute Engine (GCE) this library enable higher total throughput across large workloads that run * on hundreds or thousands of VMs. * *

At present, GCS gRPC is GA with Allowlist. To access this API, kindly contact the Google Cloud * Storage gRPC team at [email protected] with a list of GCS buckets you would like to * Allowlist. Please note that while the **service** is GA (with Allowlist), the client library * features remain experimental and subject to change without notice. The methods to create, list, * query, and delete HMAC keys and notifications are unavailable in gRPC transport. * *

This example shows how to enable gRPC with Direct Google Access only supported on Google * Compute Engine. * *

{@code
 * StorageOptions options = StorageOptions.grpc().setAttemptDirectPath(true).build();
 * try (Storage storage = options.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();
 * }
 * }
 * }
* *

This example shows how to enable gRPC. * *

{@code
 * StorageOptions options = StorageOptions.grpc().build();
 * try (Storage storage = options.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();
 * }
 * }
 * }
* * @see Google Cloud Storage */ package com.google.cloud.storage;




© 2015 - 2024 Weber Informatics LLC | Privacy Policy