Java Code Examples for com.google.api.services.storage.Storage#Builder

The following examples show how to use com.google.api.services.storage.Storage#Builder . 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: Transport.java    From beam with Apache License 2.0 6 votes vote down vote up
/** Returns a Cloud Storage client builder using the specified {@link GcsOptions}. */
public static Storage.Builder newStorageClient(GcsOptions options) {
  String servicePath = options.getGcsEndpoint();
  Storage.Builder storageBuilder =
      new Storage.Builder(
              getTransport(),
              getJsonFactory(),
              chainHttpRequestInitializer(
                  options.getGcpCredential(),
                  // Do not log the code 404. Code up the stack will deal with 404's if needed,
                  // and
                  // logging it by default clutters the output during file staging.
                  new RetryHttpRequestInitializer(
                      ImmutableList.of(404), new UploadIdResponseInterceptor())))
          .setApplicationName(options.getAppName())
          .setGoogleClientRequestInitializer(options.getGoogleApiTrace());
  if (servicePath != null) {
    ApiComponents components = apiComponentsFromUrl(servicePath);
    storageBuilder.setRootUrl(components.rootUrl);
    storageBuilder.setServicePath(components.servicePath);
    storageBuilder.setBatchPath(Paths.get("batch/", components.servicePath).toString());
  }
  return storageBuilder;
}
 
Example 2
Source File: GoogleApiFactory.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Override
public Storage newStorageApi(Credential credential) {
  Preconditions.checkNotNull(transportCache, "transportCache is null");
  HttpTransport transport = transportCache.getUnchecked(GoogleApi.CLOUD_STORAGE_API);
  Preconditions.checkNotNull(transport, "transport is null");
  Preconditions.checkNotNull(jsonFactory, "jsonFactory is null");

  Storage.Builder builder = new Storage.Builder(transport, jsonFactory, credential)
      .setApplicationName(CloudToolsInfo.USER_AGENT);
  Storage storage = builder.build();
  return storage;
}
 
Example 3
Source File: GcsUtil.java    From beam with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an instance of {@link GcsUtil} based on the {@link PipelineOptions}.
 *
 * <p>If no instance has previously been created, one is created and the value stored in {@code
 * options}.
 */
@Override
public GcsUtil create(PipelineOptions options) {
  LOG.debug("Creating new GcsUtil");
  GcsOptions gcsOptions = options.as(GcsOptions.class);
  Storage.Builder storageBuilder = Transport.newStorageClient(gcsOptions);
  return new GcsUtil(
      storageBuilder.build(),
      storageBuilder.getHttpRequestInitializer(),
      gcsOptions.getExecutorService(),
      hasExperiment(options, "use_grpc_for_gcs"),
      gcsOptions.getGcsUploadBufferSizeBytes());
}
 
Example 4
Source File: GCSOptions.java    From dataflow-java with Apache License 2.0 5 votes vote down vote up
public static Storage.Objects createStorageClient(GCSOptions gcsOptions,
  OfflineAuth auth) {
final Storage.Builder storageBuilder = new Storage.Builder(
    gcsOptions.getTransport(),
    gcsOptions.getJsonFactory(),
    null);

return gcsOptions.getGenomicsFactory()
    .fromOfflineAuth(storageBuilder, auth)
    .build()
    .objects();
}