Skip to content

Commit 6ce7fc9

Browse files
jean-philippe-martinsduskis
authored andcommitted
---
yaml --- r: 22019 b: refs/heads/autosynth-video-intelligence c: f574484 h: refs/heads/master i: 22017: bac4c6d 22015: 8df8f02
1 parent b1b55c4 commit 6ce7fc9

5 files changed

Lines changed: 58 additions & 4 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ refs/heads/autosynth-compute: 026cea73fde22ec0b40866ac5a7dc144dc465b9b
115115
refs/heads/autosynth-container: d17e1a76a903f9e05eba56a9bf5d12c1b15b67d7
116116
refs/heads/autosynth-monitoring: e66569bd7358a90d17097f90cf8c70dbeeb048cf
117117
refs/heads/autosynth-pubsub: 39d0c11469a8084ece7c1ff58809f24da0316ae6
118-
refs/heads/autosynth-video-intelligence: bd8d2cecdfb56b35d41a86697eda279e34f19bcf
118+
refs/heads/autosynth-video-intelligence: f5744849a2bb093b21577730984510f657968526
119119
refs/heads/autosynth-vision: 7d58f59617722175b83a4583efdb6eb9b5b8e8dd
120120
refs/heads/spanner: b01127f885b4611bf1852abb0ce481eeb7fcc131
121121
refs/tags/v0.68.0: 9cc799fcf68c82ab431d425fefa58ef615ce8e5b

branches/autosynth-video-intelligence/google-cloud-clients/google-cloud-contrib/google-cloud-nio-examples/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ application that uses Java NIO without the need to recompile.
66

77
Note that whenever possible, you instead want to recompile the app and use the normal
88
dependency mechanism to add a dependency to google-cloud-nio. You can see examples of
9-
this in the [google-cloud-examples](../../../google-cloud-examples) project.
9+
this in the [google-cloud-examples](../../../google-cloud-examples) project,
10+
[under nio](../../../google-cloud-examples/src/main/java/com/google/cloud/examples/nio).
1011

1112
To run this example:
1213

branches/autosynth-video-intelligence/google-cloud-clients/google-cloud-contrib/google-cloud-nio/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ Authentication
5757
--------------
5858

5959
See the [Authentication](https://github.com/googleapis/google-cloud-java#authentication)
60-
section in the base directory's README.
60+
section in the base directory's README. This shows how to construct the `StorageOptions` object,
61+
which you can then pass to `CloudStorageFileSystem.forBucket`.
6162

6263
About Google Cloud Storage
6364
--------------------------

branches/autosynth-video-intelligence/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ protected Path computeNext() {
140140
}
141141
}
142142

143-
/** Sets options that are only used by the constructor. */
143+
/**
144+
* Sets options that are only used by the constructor.
145+
*
146+
* <p>Instead of calling this, when possible use CloudStorageFileSystem.forBucket and pass
147+
* StorageOptions as an argument.
148+
*/
144149
@VisibleForTesting
145150
public static void setStorageOptions(@Nullable StorageOptions newStorageOptions) {
146151
futureStorageOptions = newStorageOptions;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.examples.nio.snippets;
18+
19+
import com.google.auth.oauth2.ServiceAccountCredentials;
20+
import com.google.cloud.storage.StorageOptions;
21+
import com.google.cloud.storage.contrib.nio.CloudStorageConfiguration;
22+
import com.google.cloud.storage.contrib.nio.CloudStorageFileSystem;
23+
import java.io.FileInputStream;
24+
import java.io.IOException;
25+
26+
/**
27+
* A snippet for Google Cloud Storage NIO that shows how to create a {@link CloudStorageFileSystem}
28+
* using explicitly-provided credentials instead of the default ones.
29+
*/
30+
public class UseExplicitCredentials {
31+
32+
public static void main(String... args) throws IOException {
33+
// Create a file system for the bucket using the service account credentials
34+
// saved in the file below.
35+
String myCredentials = "/path/to/my/key.json";
36+
CloudStorageFileSystem fs =
37+
CloudStorageFileSystem.forBucket(
38+
"mybucket",
39+
CloudStorageConfiguration.DEFAULT,
40+
StorageOptions.newBuilder()
41+
.setCredentials(
42+
ServiceAccountCredentials.fromStream(new FileInputStream(myCredentials)))
43+
.build());
44+
// Can now read and write to the bucket using fs
45+
// (see e.g. ReadAllLines for an example).
46+
}
47+
}

0 commit comments

Comments
 (0)