use of com.google.cloud.storage.StorageClass in project google-cloud-java by GoogleCloudPlatform.
the class ChangeDefaultStorageClass method changeDefaultStorageClass.
public static void changeDefaultStorageClass(String projectId, String bucketName) {
// The ID of your GCP project
// String projectId = "your-project-id";
// The ID of your GCS bucket
// String bucketName = "your-unique-bucket-name";
// See the StorageClass documentation for other valid storage classes:
// https://googleapis.dev/java/google-cloud-clients/latest/com/google/cloud/storage/StorageClass.html
StorageClass storageClass = StorageClass.COLDLINE;
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
Bucket bucket = storage.get(bucketName);
bucket = bucket.toBuilder().setStorageClass(storageClass).build().update();
System.out.println("Default storage class for bucket " + bucketName + " has been set to " + bucket.getStorageClass());
}
use of com.google.cloud.storage.StorageClass in project google-cloud-java by GoogleCloudPlatform.
the class ChangeObjectStorageClass method changeObjectStorageClass.
public static void changeObjectStorageClass(String projectId, String bucketName, String objectName) {
// The ID of your GCP project
// String projectId = "your-project-id";
// The ID of your GCS bucket
// String bucketName = "your-unique-bucket-name";
// The ID of your GCS object
// String objectName = "your-object-name";
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
BlobId blobId = BlobId.of(bucketName, objectName);
// See the StorageClass documentation for other valid storage classes:
// https://googleapis.dev/java/google-cloud-clients/latest/com/google/cloud/storage/StorageClass.html
StorageClass storageClass = StorageClass.COLDLINE;
// You can't change an object's storage class directly, the only way is to rewrite the object
// with the
// desired storage class
Storage.CopyRequest request = Storage.CopyRequest.newBuilder().setSource(blobId).setTarget(BlobInfo.newBuilder(blobId).setStorageClass(storageClass).build()).build();
Blob updatedBlob = storage.copy(request).getResult();
System.out.println("Object " + objectName + " in bucket " + bucketName + " had its storage class set to " + updatedBlob.getStorageClass().name());
}
use of com.google.cloud.storage.StorageClass in project google-cloud-java by GoogleCloudPlatform.
the class CreateBucketWithStorageClassAndLocation method createBucketWithStorageClassAndLocation.
public static void createBucketWithStorageClassAndLocation(String projectId, String bucketName) {
// The ID of your GCP project
// String projectId = "your-project-id";
// The ID to give your GCS bucket
// String bucketName = "your-unique-bucket-name";
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
// See the StorageClass documentation for other valid storage classes:
// https://googleapis.dev/java/google-cloud-clients/latest/com/google/cloud/storage/StorageClass.html
StorageClass storageClass = StorageClass.COLDLINE;
// See this documentation for other valid locations:
// http://g.co/cloud/storage/docs/bucket-locations#location-mr
String location = "ASIA";
Bucket bucket = storage.create(BucketInfo.newBuilder(bucketName).setStorageClass(storageClass).setLocation(location).build());
System.out.println("Created bucket " + bucket.getName() + " in " + bucket.getLocation() + " with storage class " + bucket.getStorageClass());
}
Aggregations