提交 7034e9cf 编写于 作者: S Stephan Ewen

[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.
上级 a49f0378
......@@ -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());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册