@@ -95,15 +95,49 @@ public static String generateBucketName() {
9595 return BUCKET_NAME_PREFIX + UUID .randomUUID ().toString ();
9696 }
9797
98+ /**
99+ * Creates a {@code RemoteGcsHelper} object for the given project id and JSON key input stream.
100+ *
101+ * @param projectId id of the project to be used for running the tests
102+ * @param keyStream input stream for a JSON key
103+ * @return A {@code RemoteGcsHelper} object for the provided options.
104+ * @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if
105+ * {@code keyStream} is not a valid JSON key stream
106+ */
107+ public static RemoteGcsHelper create (String projectId , InputStream keyStream )
108+ throws GcsHelperException {
109+ try {
110+ StorageOptions storageOptions = StorageOptions .builder ()
111+ .authCredentials (AuthCredentials .createForJson (keyStream ))
112+ .projectId (projectId )
113+ .retryParams (RetryParams .builder ()
114+ .retryMaxAttempts (10 )
115+ .retryMinAttempts (6 )
116+ .maxRetryDelayMillis (30000 )
117+ .totalRetryPeriodMillis (120000 )
118+ .initialRetryDelayMillis (250 )
119+ .build ())
120+ .connectTimeout (60000 )
121+ .readTimeout (60000 )
122+ .build ();
123+ return new RemoteGcsHelper (storageOptions );
124+ } catch (IOException ex ) {
125+ if (log .isLoggable (Level .WARNING )) {
126+ log .log (Level .WARNING , ex .getMessage ());
127+ }
128+ throw GcsHelperException .translate (ex );
129+ }
130+ }
131+
98132 /**
99133 * Creates a {@code RemoteGcsHelper} object for the given project id and JSON key path.
100134 *
101135 * @param projectId id of the project to be used for running the tests
102136 * @param keyPath path to the JSON key to be used for running the tests
103137 * @param options creation options
104138 * @return A {@code RemoteGcsHelper} object for the provided options.
105- * @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if the file pointed by
106- * {@code keyPath} does not exist
139+ * @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if the file
140+ * pointed by {@code keyPath} does not exist
107141 */
108142 public static RemoteGcsHelper create (String projectId , String keyPath , Option ... options )
109143 throws GcsHelperException {
@@ -123,20 +157,7 @@ public static RemoteGcsHelper create(String projectId, String keyPath, Option...
123157 } else {
124158 keyFileStream = new FileInputStream (keyPath );
125159 }
126- StorageOptions storageOptions = StorageOptions .builder ()
127- .authCredentials (AuthCredentials .createForJson (keyFileStream ))
128- .projectId (projectId )
129- .retryParams (RetryParams .builder ()
130- .retryMaxAttempts (10 )
131- .retryMinAttempts (6 )
132- .maxRetryDelayMillis (30000 )
133- .totalRetryPeriodMillis (120000 )
134- .initialRetryDelayMillis (250 )
135- .build ())
136- .connectTimeout (60000 )
137- .readTimeout (60000 )
138- .build ();
139- return new RemoteGcsHelper (storageOptions );
160+ return create (projectId , keyFileStream );
140161 } catch (FileNotFoundException ex ) {
141162 if (log .isLoggable (Level .WARNING )) {
142163 log .log (Level .WARNING , ex .getMessage ());
@@ -156,9 +177,9 @@ public static RemoteGcsHelper create(String projectId, String keyPath, Option...
156177 *
157178 * @param options creation options
158179 * @return A {@code RemoteGcsHelper} object for the provided options.
159- * @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if environment variables
160- * {@code GCLOUD_TESTS_PROJECT_ID} and {@code GCLOUD_TESTS_KEY} are not set or if the file
161- * pointed by {@code GCLOUD_TESTS_KEY} does not exist
180+ * @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if environment
181+ * variables {@code GCLOUD_TESTS_PROJECT_ID} and {@code GCLOUD_TESTS_KEY} are not set or if
182+ * the file pointed by {@code GCLOUD_TESTS_KEY} does not exist
162183 */
163184 public static RemoteGcsHelper create (Option ... options ) throws GcsHelperException {
164185 String projectId = System .getenv (PROJECT_ID_ENV_VAR );
0 commit comments