You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by se...@apache.org on 2018/01/05 18:39:00 UTC

[19/19] flink git commit: [hotfix] [core] Add a factory method to create Path from local file

[hotfix] [core] Add a factory method to create Path from local file

This makes it easier for users and contributors to figure out how
to create local file paths in way that works cross operating systems.


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

Branch: refs/heads/master
Commit: 7034e9cfcb051ef90c5bf0960bfb50a79b3723f0
Parents: a49f037
Author: Stephan Ewen <se...@apache.org>
Authored: Wed Dec 13 17:06:37 2017 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Fri Jan 5 19:38:07 2018 +0100

----------------------------------------------------------------------
 .../java/org/apache/flink/core/fs/Path.java     | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/7034e9cf/flink-core/src/main/java/org/apache/flink/core/fs/Path.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/core/fs/Path.java b/flink-core/src/main/java/org/apache/flink/core/fs/Path.java
index b463fd9..1334acc 100644
--- a/flink-core/src/main/java/org/apache/flink/core/fs/Path.java
+++ b/flink-core/src/main/java/org/apache/flink/core/fs/Path.java
@@ -28,6 +28,7 @@ import org.apache.flink.core.memory.DataInputView;
 import org.apache.flink.core.memory.DataOutputView;
 import org.apache.flink.util.StringUtils;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.Serializable;
 import java.net.URI;
@@ -528,4 +529,23 @@ public class Path implements IOReadableWritable, Serializable {
 				&& ((path.charAt(start) >= 'A' && path.charAt(start) <= 'Z') || (path.charAt(start) >= 'a' && path
 				.charAt(start) <= 'z'));
 	}
+
+	// ------------------------------------------------------------------------
+	//  Utilities
+	// ------------------------------------------------------------------------
+
+	/**
+	 * Creates a path for the given local file.
+	 *
+	 * <p>This method is useful to make sure the path creation for local files works
+	 * seamlessly across different operating systems. Especially Windows has slightly
+	 * different rules for slashes between schema and a local file path, making it
+	 * sometimes tricky to produce cross-platform URIs for local files.
+	 *
+	 * @param file The file that the path should represent.
+	 * @return A path representing the local file URI of the given file.
+	 */
+	public static Path fromLocalFile(File file) {
+		return new Path(file.toURI());
+	}
 }