本文整理汇总了Java中com.google.cloud.storage.StorageOptions类的典型用法代码示例。如果您正苦于以下问题:Java StorageOptions类的具体用法?Java StorageOptions怎么用?Java StorageOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StorageOptions类属于com.google.cloud.storage包,在下文中一共展示了StorageOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tearDownClass
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
@AfterClass
public static void tearDownClass() {
// Clear the datastore
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
Batch batch = datastore.newBatch();
StructuredQuery<Key> query = Query.newKeyQueryBuilder()
.setKind("Book3").build();
for (QueryResults<Key> keys = datastore.run(query); keys.hasNext(); ) {
batch.delete(keys.next());
}
batch.submit();
// Delete any objects in the bucket
Storage storage = StorageOptions.getDefaultInstance().getService();
Page<Blob> blobs = storage.list(System.getProperty("bookshelf.bucket"));
List<BlobId> blobIds = new ArrayList<BlobId>();
for (Blob b : blobs.iterateAll()) {
blobIds.add(b.getBlobId());
}
storage.delete(blobIds);
service.stop();
}
示例2: tearDownClass
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
@AfterClass
public static void tearDownClass() {
// Delete any objects in the bucket
Storage storage = StorageOptions.getDefaultInstance().getService();
Page<Blob> blobs = storage.list(System.getProperty("bookshelf.bucket"));
List<BlobId> blobIds = new ArrayList<BlobId>();
for (Blob b : blobs.iterateAll()) {
blobIds.add(b.getBlobId());
}
storage.delete(blobIds);
// Clear the datastore if we're not using the local emulator
if (!LOCAL_TEST) {
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
Batch batch = datastore.newBatch();
StructuredQuery<Key> query = Query.newKeyQueryBuilder()
.setKind("Book3").build();
for (QueryResults<Key> keys = datastore.run(query); keys.hasNext(); ) {
batch.delete(keys.next());
}
batch.submit();
}
service.stop();
}
示例3: setGenerousTimeouts
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
private static StorageOptions.Builder setGenerousTimeouts(StorageOptions.Builder builder) {
return builder
.setTransportOptions(HttpTransportOptions.newBuilder()
.setConnectTimeout(120000)
.setReadTimeout(120000)
.build())
.setRetrySettings(RetrySettings.newBuilder()
.setMaxAttempts(15)
.setMaxRetryDelay(Duration.ofMillis(256_000L))
.setTotalTimeout(Duration.ofMillis(4000_000L))
.setInitialRetryDelay(Duration.ofMillis(1000L))
.setRetryDelayMultiplier(2.0)
.setInitialRpcTimeout(Duration.ofMillis(180_000L))
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(Duration.ofMillis(180_000L))
.build());
}
示例4: getInstance
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
public static synchronized StorageClient getInstance(FirebaseApp app) {
StorageClientService service = ImplFirebaseTrampolines.getService(app, SERVICE_ID,
StorageClientService.class);
if (service == null) {
Storage storage = StorageOptions.newBuilder()
.setCredentials(ImplFirebaseTrampolines.getCredentials(app))
.build()
.getService();
StorageClient client = new StorageClient(app, storage);
service = ImplFirebaseTrampolines.addService(app, new StorageClientService(client));
}
return service.getInstance();
}
示例5: buildStorage
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
@VisibleForTesting
Storage buildStorage(HttpClient client)
{
return StorageOptions
.newBuilder()
.setRetrySettings(buildRetrySettings())
.setTransportOptions(buildTransportOptions(client))
.setClock(NanoClock.getDefaultClock())
.setProjectId(getProjectId())
.build()
.getService();
}
示例6: configureStorageFromEnvironment
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
public void configureStorageFromEnvironment()
throws IOException {
String json = credentialJsonFromEnv();
Optional<String> projectId = projectFromJsonCredential(json);
if (projectId.isPresent()) {
storage = StorageOptions.newBuilder()
.setCredentials(ServiceAccountCredentials.fromStream(new FileInputStream(jsonCredentialPath())))
.setProjectId(projectId.get())
.build()
.getService();
} else {
LOGGER.info("Unable to initiate storage. Check the credentials in path: "
+ jsonCredentialPath());
}
}
示例7: getStorageService
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
private Storage getStorageService() {
StorageOptions storageOptions = StorageOptions.getDefaultInstance();
if (project().isPresent()) {
storageOptions = StorageOptions.newBuilder()
.setProjectId(project().get())
.build();
}
return storageOptions.getService();
}
示例8: apply
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
@Override
public String apply(String gcspath) {
Storage storage = StorageOptions.getDefaultInstance().getService();
String bucketName = gcspath.replace("gs://", "").split("/")[0];
String blobName = gcspath.replace("gs://" + bucketName + "/", "");
Blob blob = storage.get(bucketName, blobName);
if (!blob.exists()) {
throw new IllegalArgumentException("File does not exists in gcs(" + gcspath + ")");
}
return new String(blob.getContent());
}
示例9: exec
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
@TaskAction
public void exec() {
ImmutableGcloudExtension config = getProject().getExtensions().getByType(GcloudExtension.class);
Storage cloudStorage =
StorageOptions.newBuilder().setProjectId(config.clusterProject()).build().getService();
cloudStorage
.create(BucketInfo.of(config.buildCacheStorageBucket()))
.createAcl(Acl.of(new Domain("istellar.jp"), Role.READER));
}
示例10: createBuildCacheService
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
@Override
public BuildCacheService createBuildCacheService(
CloudStorageBuildCache buildCache, Describer describer) {
checkNotNull(buildCache.getBucket(), "buildCache.bucket");
describer.type("Google Cloud Storage Build Cache").config("bucket", buildCache.getBucket());
Storage cloudStorage =
StorageOptions.newBuilder().setProjectId(buildCache.getProject()).build().getService();
return new CloudStorageBuildCacheService(cloudStorage, buildCache.getBucket());
}
示例11: storage
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public static Storage storage(CredentialsProvider credentialsProvider,
GcpStorageProperties gcpStorageProperties) throws IOException {
return StorageOptions.newBuilder()
.setCredentials(gcpStorageProperties.getCredentials().getLocation() != null
? GoogleCredentials
.fromStream(gcpStorageProperties.getCredentials()
.getLocation().getInputStream())
.createScoped(gcpStorageProperties.getCredentials().getScopes())
: credentialsProvider.getCredentials())
.build().getService();
}
示例12: setConfig
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
@Override
public void setConfig(Map<String, String> config) {
String prefix = StringUtils.trimToNull(config.get("prefix"));
if (prefix == null) {
throw new RuntimeException("Prefix not set in " + config);
}
if (storage == null) {
String projectId = StringUtils.trimToNull(config.get("projectid"));
if (projectId == null) {
projectId = MultiValueConfigLoader.getConfig("GOOGLE-projectid");
if (projectId == null) {
throw new RuntimeException("Project ID not set in RaptureGOOGLE.cfg or in config " + config);
}
}
storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
}
// NOTE cannot currently use a full stop in a bucket name.
bucketName = environment + prefix.replaceAll("[\\./]", "").toLowerCase();
try {
bucket = storage.get(bucketName);
} catch (StorageException e) {
System.out.println("Cannot find bucket " + bucketName);
e.printStackTrace();
}
if (bucket == null) bucket = storage.create(BucketInfo.of(bucketName));
}
示例13: TestApp
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
public TestApp() {
try
{
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
//ComputeCredential credential = new ComputeCredential.Builder(httpTransport, jsonFactory).build();
GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport,jsonFactory);
if (credential.createScopedRequired())
credential = credential.createScoped(Arrays.asList(Oauth2Scopes.USERINFO_EMAIL));
Oauth2 service = new Oauth2.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("oauth client")
.build();
Userinfoplus ui = service.userinfo().get().execute();
System.out.println(ui.getEmail());
// Using Google Cloud APIs
Storage storage_service = StorageOptions.defaultInstance().service();
Iterator<Bucket> bucketIterator = storage_service.list().iterateAll();
while (bucketIterator.hasNext()) {
System.out.println(bucketIterator.next());
}
}
catch (Exception ex) {
System.out.println("Error: " + ex);
}
}
示例14: doGet
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
HttpTransport httpTransport = new UrlFetchTransport();
JacksonFactory jsonFactory = new JacksonFactory();
/*
AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();
AppIdentityService.GetAccessTokenResult accessToken = appIdentity.getAccessToken(Arrays.asList(Oauth2Scopes.USERINFO_EMAIL));
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory).build();
credential.setAccessToken(accessToken.getAccessToken());
*/
GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport,jsonFactory);
if (credential.createScopedRequired())
credential = credential.createScoped(Arrays.asList(Oauth2Scopes.USERINFO_EMAIL));
Oauth2 service = new Oauth2.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("oauth client").build();
Userinfoplus ui = service.userinfo().get().execute();
resp.getWriter().println(ui.getEmail());
// Using Google Cloud APIs
Storage storage_service = StorageOptions.defaultInstance().service();
Iterator<Bucket> bucketIterator = storage_service.list().iterateAll();
while (bucketIterator.hasNext()) {
System.out.println(bucketIterator.next());
}
}
示例15: main
import com.google.cloud.storage.StorageOptions; //导入依赖的package包/类
public static void main(String... args) throws Exception {
// Instantiates a client
Storage storage = StorageOptions.getDefaultInstance().getService();
// The name for the new bucket
String bucketName = args[0]; // "my-new-bucket";
// Creates the new bucket
Bucket bucket = storage.create(BucketInfo.of(bucketName));
System.out.printf("Bucket %s created.%n", bucket.getName());
}