Package com.nordstrom.common.file
Class PathUtils
- java.lang.Object
-
- com.nordstrom.common.file.PathUtils
-
public final class PathUtils extends Object
This utility class provides agetNextPath
method to acquire the next file path in sequence for the specified base name and extension in the indicated target folder. If the target folder already contains at least one file that matches the specified base name and extension, the algorithm used to select the next path will always return a path whose index is one more than the highest index that currently exists. (If a single file with no index is found, its implied index is 0.)Example usage of
getNextPath
... /* * This example gets the next path in sequence for base name `artifact` * and extension `txt` in the TestNG output directory. * * For purposes of this example, the output directory already contains * the following files: `artifact.txt`, `artifact-3.txt` */ Path collectionPath = Paths.get(testContext.getOutputDirectory()); // => C:\git\my-project\test-output\Default suite Path artifactPath; try { artifactPath = PathUtils.getNextPath(collectionPath, "artifact", "txt"); // => C:\git\my-project\test-output\Default suite\artifact-4.txt } catch (IOException e) { provider.getLogger().info("Unable to get output path; no artifact was captured", e); return; } ...
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
PathUtils.PathModifier
Classes that implement this interface are called to supply additional elements for the path returned byPathUtils.ReportsDirectory.getPathForObject(Object)
.static class
PathUtils.ReportsDirectory
This enumeration contains methods to help build proxy subclass names and select reports directories.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String[]
append(String suffix, String... strings)
Append the specified string to the indicated array.static String
getBaseDir()
Get project base directory.static Path
getNextPath(Path targetPath, String baseName, String extension)
Get the next available path in sequence for the specified base name and extension in the specified folder.static String[]
prepend(String prefix, String... strings)
Prepend the specified string to the indicated array.
-
-
-
Method Detail
-
getNextPath
public static Path getNextPath(Path targetPath, String baseName, String extension) throws IOException
Get the next available path in sequence for the specified base name and extension in the specified folder.- Parameters:
targetPath
- path to target directory for the next available path in sequencebaseName
- base name for the path sequenceextension
- extension for the path sequence- Returns:
- the next available path in sequence
- Throws:
IOException
- if an I/O error is thrown when accessing the starting file.
-
getBaseDir
public static String getBaseDir()
Get project base directory.- Returns:
- project base directory
-
prepend
public static String[] prepend(String prefix, String... strings)
Prepend the specified string to the indicated array.- Parameters:
prefix
- string to be prependedstrings
- target string array- Returns:
- target array prefixed with the specified string
-
-