Java Code Examples for com.google.cloud.storage.Storage#list()

The following examples show how to use com.google.cloud.storage.Storage#list() . 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 File: ITTranslateSnippetsBeta.java    From google-cloud-java with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: StreamingAnnotationToStorageIT.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: DetectIT.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: DetectIT.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: BatchTranslateTextWithGlossaryTests.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
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 6
Source File: StorageSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
/** 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]
}
 
Example 7
Source File: ListBuckets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
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 8
Source File: StreamingAnnotationToStorageIT.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
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 9
Source File: AsyncBatchAnnotateImagesTest.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: BatchTranslateTextWithGlossaryTests.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
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 File: AuthExample.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
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 12
Source File: BatchTranslateTextWithGlossaryAndModelTests.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
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 File: BatchTranslateTextWithGlossaryAndModelTests.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
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 File: BatchTranslateTextTests.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
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 File: BatchTranslateTextTests.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
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 16
Source File: BatchTranslateTextWithModelTests.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
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 File: BatchTranslateTextWithModelTests.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
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 18
Source File: AuthExample.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
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 19
Source File: ITTranslateSnippetsBeta.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
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 20
Source File: AuthExample.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
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());
  }
}