diff --git a/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystem.java b/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystem.java index 60a39fb5a817..4f031c92f740 100644 --- a/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystem.java +++ b/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystem.java @@ -27,6 +27,7 @@ import java.net.URISyntaxException; import java.nio.file.FileStore; import java.nio.file.FileSystem; +import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.PathMatcher; import java.nio.file.WatchService; @@ -210,13 +211,9 @@ public Set supportedFileAttributeViews() { return SUPPORTED_VIEWS; } - /** - * Throws {@link UnsupportedOperationException} because this feature hasn't been implemented yet. - */ @Override public PathMatcher getPathMatcher(String syntaxAndPattern) { - // TODO(#813): Implement me. - throw new UnsupportedOperationException(); + return FileSystems.getDefault().getPathMatcher(syntaxAndPattern); } /** diff --git a/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java b/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java index ec856447b96a..d7d5b346c376 100644 --- a/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java +++ b/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java @@ -34,6 +34,7 @@ import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.PathMatcher; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -159,4 +160,27 @@ public void testListFiles() throws IOException { assertThat(got).containsExactlyElementsIn(goodPaths); } } + + @Test + public void testMatcher() throws IOException { + try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) { + String pattern1 = "glob:*.java"; + PathMatcher javaFileMatcher = fs.getPathMatcher(pattern1); + assertMatches(fs, javaFileMatcher, "a.java", true); + assertMatches(fs, javaFileMatcher, "a.text", false); + assertMatches(fs, javaFileMatcher, "folder/c.java", true); + assertMatches(fs, javaFileMatcher, "d", false); + + String pattern2 = "glob:*.{java,text}"; + PathMatcher javaAndTextFileMatcher = fs.getPathMatcher(pattern2); + assertMatches(fs, javaAndTextFileMatcher, "a.java", true); + assertMatches(fs, javaAndTextFileMatcher, "a.text", true); + assertMatches(fs, javaAndTextFileMatcher, "folder/c.java", true); + assertMatches(fs, javaAndTextFileMatcher, "d", false); + } + } + + private void assertMatches(FileSystem fs, PathMatcher matcher, String toMatch, boolean expected) { + assertThat(matcher.matches(fs.getPath(toMatch).getFileName())).isEqualTo(expected); + } }