Package com.optum.sourcehawk.core.utils
Class FileUtils
- java.lang.Object
-
- com.optum.sourcehawk.core.utils.FileUtils
-
public final class FileUtils extends Object
File Utilities- Author:
- Brian Wyka
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringderiveRelativePath(String root, String absolutePath)Derive the relative path forabsolutePathrelative torootstatic Stream<Path>find(String root, String pathOrPattern)Find file paths by a glob pattern.static booleanisGlobPattern(String pattern)Determine if the provided pattern is a glob pattern
-
-
-
Method Detail
-
deriveRelativePath
public static String deriveRelativePath(String root, String absolutePath)
Derive the relative path forabsolutePathrelative toroot- Parameters:
root- the root to determine relativityabsolutePath- the absolute path- Returns:
- the path relative to the root
-
find
public static Stream<Path> find(String root, String pathOrPattern) throws IOException
Find file paths by a glob pattern.If a glob pattern is not provided, then this method will return a stream of one
Pathrepresentation for the provided arguments (if the path exists), otherwise an empty stream.In other words, this method will only ever return a stream of actual files which exist.
- Parameters:
root- the start location to searchpathOrPattern- the path or glob pattern, i.e **/path/**/*.txt- Returns:
- the collection of paths which match the pattern, or an empty collection if no matches found
- Throws:
IOException- if any error occurs walking the file tree attempting to match paths
-
isGlobPattern
public static boolean isGlobPattern(String pattern)
Determine if the provided pattern is a glob pattern- Parameters:
pattern- the pattern to check- Returns:
- true if a glob pattern, false otherwise
-
-