Skip to content

Commit

Permalink
[hotfix] [core] Add a factory method to create Path from local file
Browse files Browse the repository at this point in the history
This makes it easier for users and contributors to figure out how
to create local file paths in way that works cross operating systems.
  • Loading branch information
StephanEwen committed Jan 5, 2018
1 parent a49f037 commit 7034e9c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions flink-core/src/main/java/org/apache/flink/core/fs/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -528,4 +529,23 @@ private boolean hasWindowsDrive(String path, boolean slashed) {
&& ((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());
}
}

0 comments on commit 7034e9c

Please sign in to comment.