List of utility methods to do Path Create nio
void | createMainClassAndBuildFileWithDeps(String targetName, String deps, Path dir) create Main Class And Build File With Deps writeLinesToFile(dir.resolve("Main" + CPP_FILE_SUFFIX), "int main() {", " return 0;", "}"); appendLinesToFile(dir.resolve(BUILD_FILE_NAME), "cc_binary(", " name = '" + targetName + "',", " srcs = [ 'Main.cc' ],", deps, ")"); |
void | createOverwriteDirectory(Path path) Creates new directory or overwrites existing one. if (Files.exists(path)) {
delete(path);
Files.createDirectory(path);
|
Path | createPath(String fileName, String subfolder) create Path return Paths.get(subfolder, UUID.randomUUID() + "-" + fileName.replace("/", "-").replace("\\", "-")); |
Comparator | createPathComparator() create Path Comparator return new Comparator<Path>() { @Override public int compare(Path p1, Path p2) { String s1 = (p1 != null ? p1.toString() : null); String s2 = (p2 != null ? p2.toString() : null); if (s1 == null) { s1 = ""; return s1.compareTo(s2 != null ? s2 : ""); }; |
PathMatcher[] | createPathMatcher(String[] patterns) create Path Matcher if (patterns == null) { return new PathMatcher[0]; int matcherSize = patterns.length; PathMatcher[] matchers = new PathMatcher[matcherSize]; for (int i = 0; i < matcherSize; i++) { matchers[i] = FileSystems.getDefault().getPathMatcher("glob:" + patterns[i]); return matchers; |
Path | createPathOrNull(String pathString) create Path Or Null try { return Paths.get(pathString); } catch (InvalidPathException ipe) { return null; |
Function | createPathRelativizer(Path path, boolean doRelativize) create Path Relativizer return (p) -> (doRelativize ? path.relativize(p) : p);
|
Path | createProperties(final Path directory, final Properties properties) create Properties Objects.requireNonNull(directory, "directory"); Objects.requireNonNull(properties, "properties"); if (!Files.isDirectory(directory)) { throw new IllegalArgumentException("directory " + directory + " must be a directory"); Path configurationFile = directory.resolve(getConfigurationFileName()); properties.store(Files.newOutputStream(configurationFile), "configuration"); return configurationFile; ... |
void | createRandomClass(String className, Path dir) create Random Class writeLinesToFile(dir.resolve(className + CPP_FILE_SUFFIX), "#include <random>", "#include <iostream>", "#include <ctime>", "using namespace std;", "", "class " + className + " {", "public:", " static void printSth() {", " srand(time(NULL));", " int n = rand();", " cout << \"This is method(printSth) with random number(\" << n << \")\\n\";", " }", "};"); writeLinesToFile(dir.resolve(className + CPP_HEADER_FILE_SUFFIX), "class " + className + " {", "public:", " static void printSth();", "};"); |
Path | createRandomFolder(Path basePath) create Random Folder String folderName = "f" + FOLDER_NUMBER++; Path p = basePath.resolve(folderName); Files.createDirectory(p); return p; |