Search in sources :

Example 1 with CloudStorageConfiguration

use of com.google.cloud.storage.contrib.nio.CloudStorageConfiguration in project gatk by broadinstitute.

the class BucketUtils method getPathOnGcs.

/**
     * String -> Path. This *should* not be necessary (use Paths.get(URI.create(...)) instead) , but it currently is
     * on Spark because using the fat, shaded jar breaks the registration of the GCS FilesystemProvider.
     * To transform other types of string URLs into Paths, use IOUtils.getPath instead.
     */
public static java.nio.file.Path getPathOnGcs(String gcsUrl) {
    // use a split limit of -1 to preserve empty split tokens, especially trailing slashes on directory names
    final String[] split = gcsUrl.split("/", -1);
    final String BUCKET = split[2];
    final String pathWithoutBucket = String.join("/", Arrays.copyOfRange(split, 3, split.length));
    CloudStorageConfiguration cloudConfig = CloudStorageConfiguration.builder().maxChannelReopens(NIO_MAX_REOPENS).build();
    StorageOptions sopt = setGenerousTimeouts(StorageOptions.newBuilder()).build();
    return CloudStorageFileSystem.forBucket(BUCKET, cloudConfig, sopt).getPath(pathWithoutBucket);
}
Also used : StorageOptions(com.google.cloud.storage.StorageOptions) CloudStorageConfiguration(com.google.cloud.storage.contrib.nio.CloudStorageConfiguration)

Aggregations

StorageOptions (com.google.cloud.storage.StorageOptions)1 CloudStorageConfiguration (com.google.cloud.storage.contrib.nio.CloudStorageConfiguration)1