Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Google Cloud Java Client for Storage

Java idiomatic client for [Google Cloud Storage] (https://cloud.google.com/storage/).

Build Status Coverage Status Maven

Note: This client is a work-in-progress, and may occasionally make backwards-incompatible changes.

Quickstart

Add this to your pom.xml file

<dependency>
  <groupId>com.google.gcloud</groupId>
  <artifactId>gcloud-java-storage</artifactId>
  <version>0.0.10</version>
</dependency>

Example Application

StorageExample is a simple command line interface that provides some of Cloud Storage's functionality. Read more about using the application on the gcloud-java-examples docs page.

Authentication

See the Authentication section in the base directory's README.

About Google Cloud Storage

Google Cloud Storage is a durable and highly available object storage service. Google Cloud Storage is almost infinitely scalable and guarantees consistency: when a write succeeds, the latest copy of the object will be returned to any GET, globally.

See the [Google Cloud Storage docs][cloud-storage-activation] for more details on how to activate Cloud Storage for your project.

See the gcloud-java API storage documentation to learn how to interact with the Cloud Storage using this Client Library.

Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must supply credentials and a project ID if running this snippet elsewhere.

import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.gcloud.storage.Blob;
import com.google.gcloud.storage.Storage;
import com.google.gcloud.storage.StorageOptions;

import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;

Storage storage = StorageOptions.getDefaultInstance().service();
Blob blob = new Blob(storage, "bucket", "blob_name");
if (!blob.exists()) {
  storage2.create(blob.info(), "Hello, Cloud Storage!".getBytes(UTF_8));
} else {
  System.out.println("Updating content for " + blob.info().name());
  byte[] prevContent = blob.content();
  System.out.println(new String(prevContent, UTF_8));
  WritableByteChannel channel = blob.writer();
  channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
  channel.close();
}

Java Versions

Java 7 or above is required for using this client.

Testing

This library has tools to help make tests for code using Cloud Storage.

See TESTING to read more about testing.

Versioning

This library follows [Semantic Versioning] (http://semver.org/).

It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable.

Contributing

Contributions to this library are always welcome and highly encouraged.

See CONTRIBUTING for more information on how to get started.

License

Apache 2.0 - See LICENSE for more information.