You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by dh...@apache.org on 2017/05/04 16:32:58 UTC

[8/9] beam git commit: FileSystems: add match(String) for single spec

FileSystems: add match(String) for single spec


Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/f4e7c02d
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/f4e7c02d
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/f4e7c02d

Branch: refs/heads/master
Commit: f4e7c02d0a91f5df9ddcb2e868ef5adb86b3f85c
Parents: 5519fe5
Author: Dan Halperin <dh...@google.com>
Authored: Wed May 3 19:34:04 2017 -0700
Committer: Dan Halperin <dh...@google.com>
Committed: Thu May 4 09:32:45 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/beam/sdk/io/FileSystems.java   | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/beam/blob/f4e7c02d/sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileSystems.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileSystems.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileSystems.java
index 0110a0c..a3af8d9 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileSystems.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileSystems.java
@@ -19,6 +19,7 @@ package org.apache.beam.sdk.io;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Verify.verify;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
@@ -107,6 +108,22 @@ public class FileSystems {
     return getFileSystemInternal(getOnlyScheme(specs)).match(specs);
   }
 
+
+  /**
+   * Like {@link #match(List)}, but for a single resource specification.
+   *
+   * <p>The function {@link #match(List)} is preferred when matching multiple patterns, as it allows
+   * for bulk API calls to remote filesystems.
+   */
+  public static MatchResult match(String spec) throws IOException {
+    List<MatchResult> matches = match(Collections.singletonList(spec));
+    verify(
+        matches.size() == 1,
+        "FileSystem implementation for %s did not return exactly one MatchResult: %s",
+        spec,
+        matches);
+    return matches.get(0);
+  }
   /**
    * Returns the {@link Metadata} for a single file resource. Expects a resource specification
    * {@code spec} that matches a single result.