-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from saalfeldlab/feat/refactorTests
Feat/refactor tests
- Loading branch information
Showing
18 changed files
with
561 additions
and
764 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/org/janelia/saalfeldlab/googlecloud/GoogleCloudUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.janelia.saalfeldlab.googlecloud; | ||
|
||
import com.google.cloud.storage.Storage; | ||
import com.google.cloud.storage.StorageOptions; | ||
|
||
import javax.annotation.Nullable; | ||
import java.net.URI; | ||
import java.util.regex.Pattern; | ||
|
||
public class GoogleCloudUtils { | ||
|
||
public final static Pattern GS_SCHEME = Pattern.compile("gs", Pattern.CASE_INSENSITIVE); | ||
public final static Pattern GS_HOST = Pattern.compile("(cloud\\.google|storage\\.googleapis)\\.com", Pattern.CASE_INSENSITIVE); | ||
|
||
private GoogleCloudUtils() { | ||
|
||
} | ||
|
||
public static String getGoogleCloudStorageKey(String uri) { | ||
|
||
return getGoogleCloudStorageKey(URI.create(uri)); | ||
} | ||
|
||
public static String getGoogleCloudStorageKey(URI uri) { | ||
|
||
try { | ||
// if key is null, return the empty string | ||
final String key = new GoogleCloudStorageURI(uri).getKey(); | ||
return key == null ? "" : key; | ||
} catch (final Exception e) { | ||
} | ||
// parse key manually when GoogleCLoudStorageURI can't | ||
final String path = uri.getPath().replaceFirst("^/", ""); | ||
return path.substring(path.indexOf('/') + 1); | ||
} | ||
|
||
public static Storage createGoogleCloudStorage(@Nullable final String googleCloudProjectId) { | ||
|
||
final GoogleCloudStorageClient storageClient = getGoogleCloudStorageClient(googleCloudProjectId); | ||
if (storageClient == null) | ||
return null; | ||
|
||
return storageClient.create(); | ||
} | ||
|
||
public static GoogleCloudStorageClient getGoogleCloudStorageClient(@Nullable final String googleCloudProjectId) { | ||
|
||
return new GoogleCloudStorageClient(googleCloudProjectId != null ? googleCloudProjectId : | ||
StorageOptions.getDefaultProjectId()); | ||
|
||
} | ||
} |
Oops, something went wrong.