Skip to content

Commit 5c6412f

Browse files
This makes it easier for users who start with a URI describing a full
path to get a FileSystem that can work with that path, since they no longer have to needlessly remove the path from the URI. Note that Oracle's description of newFileSystem [1] puts no restriction on the passed URI. [1] https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystems.html#newFileSystem(java.net.URI,%20java.util.Map)
1 parent 27962a3 commit 5c6412f

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProvider.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ public CloudStorageFileSystem getFileSystem(URI uri) {
176176
* @param env map of configuration options, whose keys correspond to the method names of
177177
* {@link CloudStorageConfiguration.Builder}. However you are not allowed to set the working
178178
* directory, as that should be provided in the {@code uri}
179-
* @throws IllegalArgumentException if {@code uri} specifies a user, query, fragment, or scheme is
180-
* not {@value CloudStorageFileSystem#URI_SCHEME}
179+
* @throws IllegalArgumentException if {@code uri} specifies a port, user, query, or fragment, or
180+
* if scheme is not {@value CloudStorageFileSystem#URI_SCHEME}
181181
*/
182182
@Override
183183
public CloudStorageFileSystem newFileSystem(URI uri, Map<String, ?> env) {
@@ -191,11 +191,10 @@ public CloudStorageFileSystem newFileSystem(URI uri, Map<String, ?> env) {
191191
CloudStorageFileSystem.URI_SCHEME, uri);
192192
checkArgument(
193193
uri.getPort() == -1
194-
&& isNullOrEmpty(uri.getPath())
195194
&& isNullOrEmpty(uri.getQuery())
196195
&& isNullOrEmpty(uri.getFragment())
197196
&& isNullOrEmpty(uri.getUserInfo()),
198-
"GCS FileSystem URIs mustn't have: port, userinfo, path, query, or fragment: %s",
197+
"GCS FileSystem URIs mustn't have: port, userinfo, query, or fragment: %s",
199198
uri);
200199
CloudStorageUtil.checkBucket(uri.getHost());
201200
initStorage();

google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProviderTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
import java.nio.file.OpenOption;
5555
import java.nio.file.Path;
5656
import java.nio.file.Paths;
57+
import java.util.HashMap;
5758
import java.util.List;
59+
import java.util.Map;
5860

5961
/**
6062
* Unit tests for {@link CloudStorageFileSystemProvider}.
@@ -644,6 +646,12 @@ public void testProviderEquals() {
644646
assertThat(path1.getFileSystem().provider()).isNotEqualTo(path3.getFileSystem().provider());
645647
}
646648

649+
@Test
650+
public void testNewFileSystem() throws IOException {
651+
Map<String,String> env = new HashMap<>();
652+
FileSystem fs = FileSystems.newFileSystem(URI.create("gs://bucket/path/to/file"), env);
653+
}
654+
647655
private static CloudStorageConfiguration permitEmptyPathComponents(boolean value) {
648656
return CloudStorageConfiguration.builder().permitEmptyPathComponents(value).build();
649657
}

0 commit comments

Comments
 (0)