当前位置: 首页>>代码示例>>Java>>正文


Java StorageOptions类代码示例

本文整理汇总了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();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:24,代码来源:UserJourneyTestIT.java

示例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();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:26,代码来源:UserJourneyTestIT.java

示例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());
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:18,代码来源:BucketUtils.java

示例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();
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:14,代码来源:StorageClient.java

示例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();
}
 
开发者ID:drcrallen,项目名称:gswagon-maven-plugin,代码行数:13,代码来源:GSWagon.java

示例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());
  }
}
 
开发者ID:spotify,项目名称:spydra,代码行数:16,代码来源:GcpUtils.java

示例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();
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:10,代码来源:JSTransform.java

示例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());
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:15,代码来源:ValueProviderHelpers.java

示例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));
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:12,代码来源:CreateBuildCacheBucket.java

示例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());
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:13,代码来源:CloudStorageBuildCacheServiceFactory.java

示例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();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:14,代码来源:StorageAutoConfiguration.java

示例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));
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:30,代码来源:GoogleBlobStore.java

示例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);
	}
}
 
开发者ID:salrashid123,项目名称:gcpsamples,代码行数:31,代码来源:TestApp.java

示例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());
         }		

}
 
开发者ID:salrashid123,项目名称:gcpsamples,代码行数:38,代码来源:TestServlet.java

示例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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:13,代码来源:QuickstartSample.java


注:本文中的com.google.cloud.storage.StorageOptions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。