Java Code Examples for com.google.cloud.storage.Storage#list()
The following examples show how to use
com.google.cloud.storage.Storage#list() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: java-docs-samples File: DetectIT.java License: Apache License 2.0 | 6 votes |
@Test public void testDetectDocumentsGcs() throws Exception { // Act Detect.detectDocumentsGcs( "gs://" + ASSET_BUCKET + "/vision/document/custom_0773375000.pdf", "gs://" + OUTPUT_BUCKET + "/" + OUTPUT_PREFIX + "/"); // Assert String got = bout.toString(); assertThat(got).contains("OIL, GAS AND MINERAL LEASE"); Storage storage = StorageOptions.getDefaultInstance().getService(); Page<Blob> blobs = storage.list( OUTPUT_BUCKET, BlobListOption.currentDirectory(), BlobListOption.prefix(OUTPUT_PREFIX + "/")); for (Blob blob : blobs.iterateAll()) { blob.delete(); } }
Example 2
Source Project: java-docs-samples File: DetectIT.java License: Apache License 2.0 | 6 votes |
@Test public void testAsyncBatchAnnotateImagesGcs() throws Exception { // Act AsyncBatchAnnotateImagesGcs.asyncBatchAnnotateImagesGcs( "gs://cloud-samples-data/vision/label/wakeupcat.jpg", "gs://" + OUTPUT_BUCKET + "/" + OUTPUT_PREFIX + "/"); // Assert String got = bout.toString(); assertThat(got).contains("red:"); Storage storage = StorageOptions.getDefaultInstance().getService(); Page<Blob> blobs = storage.list(OUTPUT_BUCKET, BlobListOption.currentDirectory(), BlobListOption.prefix(OUTPUT_PREFIX + "/")); for (Blob blob : blobs.iterateAll()) { blob.delete(); } }
Example 3
Source Project: java-docs-samples File: StreamingAnnotationToStorageIT.java License: Apache License 2.0 | 6 votes |
@Test public void testStreamingAnnotationToStorage() { String gcsUri = String.format("gs://%s/%s", PROJECT_ID, OUTPUT_PREFIX); StreamingAnnotationToStorage.streamingAnnotationToStorage("resources/cat.mp4", gcsUri); String got = bout.toString(); assertThat(got).contains(String.format("Storage Uri: %s", gcsUri)); Storage storage = StorageOptions.getDefaultInstance().getService(); Page<Blob> blobs = storage.list( PROJECT_ID, BlobListOption.currentDirectory(), BlobListOption.prefix(OUTPUT_PREFIX + "/")); deleteDirectory(storage, blobs); }
Example 4
Source Project: google-cloud-java File: ITTranslateSnippetsBeta.java License: Apache License 2.0 | 6 votes |
@Test public void test1_testBatchTranslateText() { BatchTranslateResponse response = TranslateSnippetsBeta.batchTranslateText( projectId, "us-central1", "gs://cloud-samples-data/translation/text.txt", "gs://" + projectId + "/BATCH_TRANSLATION_OUTPUT/"); assertEquals(13, response.getTotalCharacters()); assertEquals(13, response.getTranslatedCharacters()); Storage storage = StorageOptions.getDefaultInstance().getService(); Page<Blob> blobs = storage.list( projectId, BlobListOption.currentDirectory(), BlobListOption.prefix("BATCH_TRANSLATION_OUTPUT/")); deleteDirectory(storage, blobs); }
Example 5
Source Project: java-docs-samples File: AuthExample.java License: Apache License 2.0 | 5 votes |
static void authImplicit() { // If you don't specify credentials when constructing the client, the client library will // look for credentials via the environment variable GOOGLE_APPLICATION_CREDENTIALS. Storage storage = StorageOptions.getDefaultInstance().getService(); System.out.println("Buckets:"); Page<Bucket> buckets = storage.list(); for (Bucket bucket : buckets.iterateAll()) { System.out.println(bucket.toString()); } }
Example 6
Source Project: java-docs-samples File: AuthExample.java License: Apache License 2.0 | 5 votes |
static void authExplicit(String jsonPath) throws IOException { // You can specify a credential file by providing a path to GoogleCredentials. // Otherwise credentials are read from the GOOGLE_APPLICATION_CREDENTIALS environment variable. GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(jsonPath)) .createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform")); Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService(); System.out.println("Buckets:"); Page<Bucket> buckets = storage.list(); for (Bucket bucket : buckets.iterateAll()) { System.out.println(bucket.toString()); } }
Example 7
Source Project: google-cloud-java File: ITTranslateSnippetsBeta.java License: Apache License 2.0 | 5 votes |
private void deleteDirectory(Storage storage, Page<Blob> blobs) { for (Blob blob : blobs.iterateAll()) { System.out.println(blob.getBlobId()); if (!blob.delete()) { Page<Blob> subBlobs = storage.list( projectId, BlobListOption.currentDirectory(), BlobListOption.prefix(blob.getName())); deleteDirectory(storage, subBlobs); } } }
Example 8
Source Project: java-docs-samples File: AuthExample.java License: Apache License 2.0 | 5 votes |
static void authAppEngineStandard() throws IOException { // Explicitly request service account credentials from the app engine standard instance. GoogleCredentials credentials = AppEngineCredentials.getApplicationDefault(); Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService(); System.out.println("Buckets:"); Page<Bucket> buckets = storage.list(); for (Bucket bucket : buckets.iterateAll()) { System.out.println(bucket.toString()); } }
Example 9
Source Project: java-docs-samples File: BatchTranslateTextWithModelTests.java License: Apache License 2.0 | 5 votes |
private static final void cleanUpBucket() { Storage storage = StorageOptions.getDefaultInstance().getService(); Page<Blob> blobs = storage.list( PROJECT_ID, Storage.BlobListOption.currentDirectory(), Storage.BlobListOption.prefix(PREFIX)); deleteDirectory(storage, blobs); }
Example 10
Source Project: java-docs-samples File: BatchTranslateTextWithModelTests.java License: Apache License 2.0 | 5 votes |
private static void deleteDirectory(Storage storage, Page<Blob> blobs) { for (Blob blob : blobs.iterateAll()) { System.out.println(blob.getBlobId()); if (!blob.delete()) { Page<Blob> subBlobs = storage.list( PROJECT_ID, Storage.BlobListOption.currentDirectory(), Storage.BlobListOption.prefix(blob.getName())); deleteDirectory(storage, subBlobs); } } }
Example 11
Source Project: java-docs-samples File: BatchTranslateTextTests.java License: Apache License 2.0 | 5 votes |
private static void cleanUpBucket() { Storage storage = StorageOptions.getDefaultInstance().getService(); Page<Blob> blobs = storage.list( PROJECT_ID, Storage.BlobListOption.currentDirectory(), Storage.BlobListOption.prefix(PREFIX)); deleteDirectory(storage, blobs); }
Example 12
Source Project: java-docs-samples File: BatchTranslateTextTests.java License: Apache License 2.0 | 5 votes |
private static void deleteDirectory(Storage storage, Page<Blob> blobs) { for (Blob blob : blobs.iterateAll()) { System.out.println(blob.getBlobId()); if (!blob.delete()) { Page<Blob> subBlobs = storage.list( PROJECT_ID, Storage.BlobListOption.currentDirectory(), Storage.BlobListOption.prefix(blob.getName())); deleteDirectory(storage, subBlobs); } } }
Example 13
Source Project: java-docs-samples File: BatchTranslateTextWithGlossaryAndModelTests.java License: Apache License 2.0 | 5 votes |
private static final void cleanUpBucket() { Storage storage = StorageOptions.getDefaultInstance().getService(); Page<Blob> blobs = storage.list( PROJECT_ID, Storage.BlobListOption.currentDirectory(), Storage.BlobListOption.prefix(PREFIX)); deleteDirectory(storage, blobs); }
Example 14
Source Project: java-docs-samples File: BatchTranslateTextWithGlossaryAndModelTests.java License: Apache License 2.0 | 5 votes |
private static void deleteDirectory(Storage storage, Page<Blob> blobs) { for (Blob blob : blobs.iterateAll()) { System.out.println(blob.getBlobId()); if (!blob.delete()) { Page<Blob> subBlobs = storage.list( PROJECT_ID, Storage.BlobListOption.currentDirectory(), Storage.BlobListOption.prefix(blob.getName())); deleteDirectory(storage, subBlobs); } } }
Example 15
Source Project: java-docs-samples File: BatchTranslateTextWithGlossaryTests.java License: Apache License 2.0 | 5 votes |
private static final void cleanUpBucket() { Storage storage = StorageOptions.getDefaultInstance().getService(); Page<Blob> blobs = storage.list( PROJECT_ID, Storage.BlobListOption.currentDirectory(), Storage.BlobListOption.prefix(PREFIX)); deleteDirectory(storage, blobs); }
Example 16
Source Project: java-docs-samples File: BatchTranslateTextWithGlossaryTests.java License: Apache License 2.0 | 5 votes |
private static void deleteDirectory(Storage storage, Page<Blob> blobs) { for (Blob blob : blobs.iterateAll()) { System.out.println(blob.getBlobId()); if (!blob.delete()) { Page<Blob> subBlobs = storage.list( PROJECT_ID, Storage.BlobListOption.currentDirectory(), Storage.BlobListOption.prefix(blob.getName())); deleteDirectory(storage, subBlobs); } } }
Example 17
Source Project: java-docs-samples File: AsyncBatchAnnotateImagesTest.java License: Apache License 2.0 | 5 votes |
@After public void tearDown() { System.setOut(null); Storage storage = StorageOptions.getDefaultInstance().getService(); Page<Blob> blobs = storage.list( PROJECT_ID, Storage.BlobListOption.currentDirectory(), Storage.BlobListOption.prefix(PREFIX)); for (Blob blob : blobs.iterateAll()) { blob.delete(); } }
Example 18
Source Project: java-docs-samples File: StreamingAnnotationToStorageIT.java License: Apache License 2.0 | 5 votes |
private void deleteDirectory(Storage storage, Page<Blob> blobs) { for (Blob blob : blobs.iterateAll()) { System.out.println(blob.getName()); if (!blob.delete()) { Page<Blob> subBlobs = storage.list( PROJECT_ID, BlobListOption.currentDirectory(), BlobListOption.prefix(blob.getName())); deleteDirectory(storage, subBlobs); } } }
Example 19
Source Project: google-cloud-java File: ListBuckets.java License: Apache License 2.0 | 5 votes |
public static void listBuckets(String projectId) { // The ID of your GCP project // String projectId = "your-project-id"; Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); Page<Bucket> buckets = storage.list(); for (Bucket bucket : buckets.iterateAll()) { System.out.println(bucket.getName()); } }
Example 20
Source Project: google-cloud-java File: StorageSnippets.java License: Apache License 2.0 | 5 votes |
/** Example of a simple listBuckets() */ public void listBuckets() { // [START storage_list_buckets] Storage storage = StorageOptions.getDefaultInstance().getService(); Page<Bucket> buckets = storage.list(); System.out.println("Buckets:"); for (Bucket bucket : buckets.iterateAll()) { System.out.println(bucket.getName()); } // [END storage_list_buckets] }