List of utility methods to do Path File Name nio
Path | getTestDataPath(Class> clazz, String name) get Test Data Path String packageName = clazz.getPackage().getName(); List<String> paths = new ArrayList<>(); paths.addAll(Arrays.asList(packageName.split("\\."))); paths.add(name); return Paths.get(RESOURCES_PATH, paths.toArray(new String[paths.size()])); |
Path | getUniqueFileInDirectory(Path dir, String name) get Unique File In Directory int extension = name.lastIndexOf('.'); return extension <= 0 || extension >= name.length() - 1 ? getUniqueFileInDirectory(dir, name, "") : getUniqueFileInDirectory(dir, name.substring(0, extension), name.substring(extension)); |
void | inheritGwtModule(Path path, String inheritableModuleLogicalName) Inherit the specified module name in the provided GWT module descriptor. final String inheritsString = " <inherits name='" + inheritableModuleLogicalName + "'/>"; List<String> content = Files.readAllLines(path, UTF_8); int i = 0, lastInheritsLine = 0; for (String str : content) { i++; if (str.contains("<inherits")) { lastInheritsLine = i; content.add(lastInheritsLine, inheritsString); Files.write(path, content, UTF_8); |
void | initializePath(String... envVarNames) initialize Path String keyEnvVarName = envVarNames[0]; Path p = DRICTORIES.get(keyEnvVarName); if (p != null) return; String directory = null; for (int i = 0; i < envVarNames.length && directory == null; ++i) { directory = System.getenv(envVarNames[i]); if (directory == null) { throw new FileNotFoundException("No " + keyEnvVarName + " directory found."); p = Paths.get(directory, SUBDIRECTORY); new File(p.toString()).mkdirs(); DRICTORIES.put(keyEnvVarName, p); |
boolean | isExecutableOnPath(String execName) is Executable On Path return Stream.of(System.getenv("PATH").split(Pattern.quote(File.pathSeparator))).map(Paths::get) .anyMatch(path -> Files.exists(path.resolve(execName))); |
boolean | isHiddenName(Path path) is Hidden Name if (path == null) return true; return path.getFileName().toString().startsWith("."); |
String | jobNameFromPath(Path path) Get job name without file extension return jobNameFromFileName(path.getFileName().toString());
|
List | listDocTypeName(Path path) list Doc Type Name return Files.walk(path, 2).filter(x -> x.getFileName().toString().endsWith("chapter.md")) .map(x -> x.getParent().getFileName().toString()).distinct().sorted().collect(Collectors.toList()); |
Path | makeUnique(Path basePath, String baseName) If the given path contains a file baseName a number is added as a suffix. Path desiredPath = Paths.get(basePath.toString(), baseName); int suffix = 0; while (Files.exists(desiredPath)) { desiredPath = Paths.get(basePath.toString(), baseName + "_" + (suffix++)); return desiredPath; |
String | pathToPackageName(Path path) path To Package Name if (path == null) { return ""; return path.toString().replace(File.separator, "."); |