You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by lc...@apache.org on 2016/07/13 19:57:12 UTC
[3/4] incubator-beam git commit: [BEAM-446] Improve
IOChannelUtils.resolve to accept multiple paths
[BEAM-446] Improve IOChannelUtils.resolve to accept multiple paths
Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/72c2c4a3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/72c2c4a3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/72c2c4a3
Branch: refs/heads/master
Commit: 72c2c4a3dbee08e636da7f8882432d6b35b1ae25
Parents: 8f5ce28
Author: Mark Liu <ma...@markliu0.mtv.corp.google.com>
Authored: Wed Jul 13 11:08:18 2016 -0700
Committer: Luke Cwik <lc...@google.com>
Committed: Wed Jul 13 12:42:07 2016 -0700
----------------------------------------------------------------------
.../apache/beam/sdk/util/IOChannelUtils.java | 21 ++++++++++++++++++++
.../beam/sdk/util/IOChannelUtilsTest.java | 11 +++++++++-
2 files changed, 31 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/72c2c4a3/sdks/java/core/src/main/java/org/apache/beam/sdk/util/IOChannelUtils.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/IOChannelUtils.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/IOChannelUtils.java
index 05443fb..1042b61 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/IOChannelUtils.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/IOChannelUtils.java
@@ -202,4 +202,25 @@ public class IOChannelUtils {
public static String resolve(String path, String other) throws IOException {
return getFactory(path).resolve(path, other);
}
+
+ /**
+ * Resolve given multiple {@code others} against the {@code path}.
+ *
+ * <p>If the {@code others} parameter contains empty paths then empty paths are ignored. If the
+ * {@code others} contains one or more absolute paths then this method returns a resulting path
+ * that starts with the last absolute path in {@code others} joining with rest paths.
+ * Otherwise this method considers the given {@code path} to be a base directory and resolves
+ * {@code others} paths against this path sequentially. Where the {@code others} paths have
+ * root components then resolution is highly implementation dependent and therefore unspecified.
+ */
+ public static String resolve(String path, String... others) throws IOException {
+ IOChannelFactory ioFactory = getFactory(path);
+ String fullPath = path;
+
+ for (String other : others) {
+ fullPath = ioFactory.resolve(fullPath, other);
+ }
+
+ return fullPath;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/72c2c4a3/sdks/java/core/src/test/java/org/apache/beam/sdk/util/IOChannelUtilsTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/util/IOChannelUtilsTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/util/IOChannelUtilsTest.java
index c79f1a1..eb35cbe 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/util/IOChannelUtilsTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/util/IOChannelUtilsTest.java
@@ -30,6 +30,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.io.File;
+import java.io.IOException;
import java.nio.charset.StandardCharsets;
/**
@@ -88,8 +89,16 @@ public class IOChannelUtilsTest {
}
@Test
- public void testResolve() throws Exception {
+ public void testResolveSinglePath() throws Exception {
String expected = tmpFolder.getRoot().toPath().resolve("aa").toString();
assertEquals(expected, IOChannelUtils.resolve(tmpFolder.getRoot().toString(), "aa"));
}
+
+ @Test
+ public void testResolveMultiplePaths() throws IOException {
+ String expected =
+ tmpFolder.getRoot().toPath().resolve("aa").resolve("bb").resolve("cc").toString();
+ assertEquals(expected,
+ IOChannelUtils.resolve(tmpFolder.getRoot().getPath(), "aa", "bb", "cc"));
+ }
}